Title: How to send XML POST request in wordpress wp_remote_post
Last modified: July 20, 2022

---

# How to send XML POST request in wordpress wp_remote_post

 *  [Choians18](https://wordpress.org/support/users/arllanz18/)
 * (@arllanz18)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/post-xml-request-error-parse-xml-errorplease-use-utf-8-encoded/)
 * Good day all. I am struggling on how to fix this error. I’ve already google this
   but cannot find any solution:(
 * I want to develop custom payment gateway plugin and integrate to an externel 
   API. I am sending request using XML POST in wordpress using wp_remote_post.
 *     ```
          public function process_payment( $order_id ) {
          $order = wc_get_order( $order_id );
   
          $url = "https://gateway.wepayez.com/pay/gateway";
          $xml = "<xml>
          <body><![CDATA[Desmark EWallet Using Gcash]]></body>  
          <callback_url><![CDATA[https://www.desmark.com.ph]]></callback_url>
          <device_info><![CDATA[12345678]]></device_info>  
          <mch_create_ip><![CDATA[127.0.0.1]]></mch_create_ip>  
          <mch_id><![CDATA[150560000001]]></mch_id>  
          <nonce_str><![CDATA[2209193392]]></nonce_str>  
          <notify_url><![CDATA[https.www.desmark.com.ph]]></notify_url>  
          <out_trade_no><![CDATA[kenttest127500000591]]></out_trade_no>  
          <service><![CDATA[unified.checkout.prepay]]></service>           
          <sign><![CDATA[CF4CB88A05435B7311F21DDCA901E5720A6EE6283C503906819A962758824BC5]]></sign>  
          <sign_type><![CDATA[SHA256]]></sign_type>
          <total_fee><![CDATA[200]]></total_fee> 
          </xml>";
   
          $response_json = wp_remote_post( 
       $url, 
       array(
           'method' => 'POST',
           'timeout' => 45,
           'redirection' => 5,
           'httpversion' => '1.0',
           'headers' => array("Content-type" => "text/xml"),
           'body' => array('xml' => $xml),
           'sslverify' => false
       )
           );  
           $response = json_encode($response_json);
           echo $response;
       ```
   
 * and this is the response i’ve got. hope someone can help me how to send request
   using the sample xml data above. you’re help means a lot to me.
 *     ```
           {"headers":{},"body":"<xml><version><![CDATA[2.0]]><\/version>\n<charset><![CDATA[UTF-8]]><\/charset>\n<status><![CDATA[400]]><\/status>\n<message><![CDATA[Parse xml error,please use UTF-8 encoded]]><\/message>\n<\/xml>","response":{"code":200,"message":"OK"},"cookies":[],"filename":null,"http_response":{"data":null,"headers":null,"status":null}}
       ```
   
 * —This is the example response that I want to get—
 *     ```
       <xml><charset><![CDATA[UTF-8]]></charset>
       <code_url><![CDATA[https://app.wepayez.com/spay/webpay?token=d852522b84fd17a928bfd4f70be4101e37713822528bd39c52b972664542e248]]></code_url>
       <mch_id><![CDATA[150560000001]]></mch_id>
       <nonce_str><![CDATA[2209193392]]></nonce_str>
       <result_code><![CDATA[0]]></result_code>
       <sign><![CDATA[D76B70E35686B1C72522A7C053F3820F1F3221D93475DD8E1B2783F9526E1196]]></sign>
       <sign_type><![CDATA[SHA256]]></sign_type>
       <status><![CDATA[0]]></status>
       <uuid><![CDATA[0256e996cec1a37de0fb8c5caba01f810]]></uuid>
       <version><![CDATA[2.0]]></version>
       </xml>
       ```
   
    -  This topic was modified 3 years, 10 months ago by [Choians18](https://wordpress.org/support/users/arllanz18/).
    -  This topic was modified 3 years, 10 months ago by [Yui](https://wordpress.org/support/users/fierevere/).
      Reason: formatting
 * The page I need help with: _[[log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fwordpress.org%2Fsupport%2Ftopic%2Fpost-xml-request-error-parse-xml-errorplease-use-utf-8-encoded%2F%3Foutput_format%3Dmd&locale=en_US)
   to see the link]_

Viewing 3 replies - 1 through 3 (of 3 total)

 *  [Dion](https://wordpress.org/support/users/diondesigns/)
 * (@diondesigns)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/post-xml-request-error-parse-xml-errorplease-use-utf-8-encoded/#post-15843041)
 * THe message is self-explanatory — your XML encoding is incorrect. You may want
   to change the `<xml>` tag to `<xml encoding="UTF-8">` and get rid of the `<charset
   >` tag. If that doesn’t work, then I suggest you ask the folks at wepayez.com
   what they require in their XML.
 *  Thread Starter [Choians18](https://wordpress.org/support/users/arllanz18/)
 * (@arllanz18)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/post-xml-request-error-parse-xml-errorplease-use-utf-8-encoded/#post-15844403)
 * Thanks for the reply sir. I will update you if it works. Thanks
 *  Thread Starter [Choians18](https://wordpress.org/support/users/arllanz18/)
 * (@arllanz18)
 * [3 years, 10 months ago](https://wordpress.org/support/topic/post-xml-request-error-parse-xml-errorplease-use-utf-8-encoded/#post-15844538)
 * [@diondesigns](https://wordpress.org/support/users/diondesigns/) hi sir. Thank
   you very much! My problem is solved. GOD bless you.
    I’ve changed the tag and
   body in wp_remote_post.
 *     ```
       $url = "https://gateway.wepayez.com/pay/gateway";
   
       $xml = "<xml version=\"1.0\" encoding=\"utf-8\">
       <body><![CDATA[Desmark EWallet Using Gcash]]></body>  
       <callback_url><![CDATA[https://www.desmark.com.ph]]></callback_url>
       <device_info><![CDATA[12345678]]></device_info>  
       <mch_create_ip><![CDATA[127.0.0.1]]></mch_create_ip>  
       <mch_id><![CDATA[150560000001]]></mch_id>  
       <nonce_str><![CDATA[2209193392]]></nonce_str>  
       <notify_url><![CDATA[https.www.desmark.com.ph]]></notify_url>  
       <out_trade_no><![CDATA[kenttest127500000591]]></out_trade_no>  
       <service><![CDATA[unified.checkout.prepay]]></service>           
       <sign><![CDATA[CF4CB88A05435B7311F21DDCA901E5720A6EE6283C503906819A962758824BC5]]></sign>  
       <sign_type><![CDATA[SHA256]]></sign_type>
       <total_fee><![CDATA[200]]></total_fee> 
       </xml>";
   
       $response_json = wp_remote_post( 
           $url, 
           array(
               'method' => 'POST',
               'timeout' => 45,
               'redirection' => 5,
               'httpversion' => '1.0',
       		'headers' => array("Content-type" => "application/xml"),
               'body' => $xml,
               'sslverify' => false
           )
       );
       ```
   

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘How to send XML POST request in wordpress wp_remote_post’ is closed to
new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 3 replies
 * 2 participants
 * Last reply from: [Choians18](https://wordpress.org/support/users/arllanz18/)
 * Last activity: [3 years, 10 months ago](https://wordpress.org/support/topic/post-xml-request-error-parse-xml-errorplease-use-utf-8-encoded/#post-15844538)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
