2

A remote server is POSTing XML to my server via RPC. I can see the XML in my Apache logs when I turn on mod security, but I can't access the XML from my PHP script. It's supposed to be a POST request, but the $_POST array is empty.

My understanding is that RPC is supposed to call my function with the data, but that doesn't seem to be happening.

This ridiculously simple script should write the XML to a log file, yet it does nothing:

include_once('xmlrpc/xmlrpc.inc');
include_once('xmlrpc/xmlrpcs.inc');

function ImportOrders($xml)
{
   $FH=fopen('Log/In.txt','a');
   fwrite($FH,'Package recieved:'.print_r($xml,true)."\n");

   // set appropriate response code
   $response = 0; // see defined response codes for this application
   // send success or failure response code
   if($response == 0)
      return new xmlrpcresp(new xmlrpcval($response, "string"));
   else
      return new xmlrpcresp(0, $response, $error_message);
}

$Server = new xmlrpc_server(
   array("ImportOrders"=>array("function"=>"ImportOrders")
   )
);

They are sending me this:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<methodCall>
<methodName>ImportOrders</methodName>
<params>
<param>
<value><int>2</int></value>
</param>
<param>
<value><struct>
<member><name>order_0</name>
<value><struct>
<member><name>order_id</name>
....

Why isn't my function being called?!?

1 Answer 1

2

Got it! Apparently the data is in "$GLOBALS['HTTP_RAW_POST_DATA']".

require 'kd_xmlrpc.php';
$xmlrpc_request = XMLRPC_parse($GLOBALS['HTTP_RAW_POST_DATA']);  
$methodName = XMLRPC_getMethodName($xmlrpc_request);    
$params = XMLRPC_getParams($xmlrpc_request);    

ImportOrders($params);

function ImportOrders($params)
{
   $FH=fopen('Log/In.txt','a');
   fwrite($FH,'OrderDataRes has been loaded.'."\n");
   fwrite($FH,'$params: '.print_r($params,true)."\n");
}

I'm also using a differnt library, from: http://www.keithdevens.com/software/xmlrpc/source.php

Not the answer you're looking for? Browse other questions tagged or ask your own question.