Hey. I'm doing some XML stuff but the book I have is pretty old (php4.0 :)
I think the reason my script keeps throwing a 400 Bad Request error is because the script entails using $request = $HTTP_RAW_POST_DATA; in the RPC server. What should I do instead of that? I've tried $request =& $POST and $request = $POST and they all throw a 400 Bad Request... I'll post the code, but it's just to get a grip on how this stuff works, so no laughing 😛
server.php
<?PHP
error_reporting(E_ALL);
$request = $HTTP_RAW_POST_DATA;
print_r($request);
// instantiate server
$rpc_server = xmlrpc_server_create() or die('Could not create RPC server.');
// register methods
xmlrpc_server_register_method($rpc_server, "doHelloWorld", "helloWorld") or die('Could not register method');
// call method
$response = xmlrpc_server_call_method($rpc_server, $request, NULL, array("verbosity"=>"no_white_space"));
// print response
echo $response;
// clean up
xmlrpc_server_destroy($rpc_server);
function helloWorld($method, $args, $add_args) {
return array('output:'=>array('hello'=>'world'));
}
?>
client.php
<?PHP
error_reporting(E_ALL);
$server = 'localhost';
$url = '/xmlstuff/server.php';
$port = 80;
$params = array('function called'=>'helloWorld');
// encode request
$request = xmlrpc_encode_request('doHelloWorld', $params, array('verbosity'=>'no_white_space'));
// open socket
$fp = fsockopen($server, $port, $errno, $errstr, 30);
if (!$fp) {
echo "$errstr ($errno)<br />\n";
} else {
$out = "POST $url HTTP/1.1\r\n";
$out.= "User-Agent: TestRPC\r\n";
$out.= "Content-Type: text/xml\r\n";
$out.= "Content-Length: ".strlen($request)."\r\n\r\n" . $request;
echo '<pre>';
print_r($out);
echo '</pre>';
fwrite($fp, $out);
while (!feof($fp)) {
echo fgets($fp, 128);
}
fclose($fp);
}
?>
I realize this code won't handle the actual xml functionality properly at the moment, I'm just trying to get the HTTP POST back and forth working to actually pass the data properly and call the method.
Any help is appreciated.