-1

I'm trying to send the data in an XML file through to an api using wordpress wp_remote_post. However when I check the response im getting 0 bytes received. I'm not to sure where I've gone wrong but any help would be appreciated. Heres the docs for reference https://help.rmscloud.com/rms-api-technical-information

<?php
$url = 'https://api.rms.com.au/rmsxml/rms_api.aspx';
$xml = 'https://spf.nz/dev/wp-content/themes/yootheme-child/rms.xml';
$args = array(
'method' => 'POST',
'timeout' => 10,
'httpversion' => '1.1',
'headers' => array(
    'Authorization' => 'Basic ' . base64_encode( 'demoagent:aREbf2875khu*' ),
    'Content-type'  => 'application/xml',
    'Content-length' => 83
),
   'body' => array($xml),
   'sslverify' => true
);


$response = wp_remote_post( $url, $args);

if ( is_wp_error( $response ) ) {
   $error_message = $response->get_error_message();
   echo "Something went wrong: $error_message";
} else {
   echo 'Response:<pre>';
   print_r( $response );
   echo '</pre>';
}



?>

XML File:

<RMSPropertyRQ>
  <Requests>
    <Request>
      <AgentId>1</AgentId>
      <RMSClientId>3038</RMSClientId>
    </Request>
    <Request>
      <AgentId>1</AgentId>
      <RMSClientId>3038</RMSClientId>
    </Request>
  </Requests>
</RMSPropertyRQ>
Jordan
  • 50
  • 1
  • 8

1 Answers1

0

Actually you are not sending XML data through wp_remote_post.

You have set 'body' => array($xml), but $xml variable is just a string containing URL. Instead of that you need to fetch xml data and sent that.

<?php
$url = 'https://api.rms.com.au/rmsxml/rms_api.aspx';
$xml = wp_remote_get('https://spf.nz/dev/wp-content/themes/yootheme-child/rms.xml');
$xml=$xml['body'];
///......
Elvin Haci
  • 3,503
  • 1
  • 17
  • 22