Passing a parameter in the header (XML RPC)

Posted by fudgey on Stack Overflow See other posts from Stack Overflow or by fudgey
Published on 2010-03-16T21:39:50Z Indexed on 2010/03/20 18:41 UTC
Read the original article Hit count: 283

Filed under:
|
|
|

I'm trying to set up a server status for the MMORPG Champions Online. I got some basic information from the web master and this is all he told me:

Now, I found a nice example to start with here, and I ended up with this code:

<?php
 ini_set('display_errors', 1);
 error_reporting(E_ALL);

# Using the XML-RPC extension to format the XML package
$request = xmlrpc_encode_request("wgsLauncher.getServerStatus", "<param><value><string>en-US</string></value></param>", null );

# Using the cURL extension to send it off, 
# first creating a custom header block
$header[] = "Host: http://www.champions-online.com:80/";
$header[] = "Content-type: text/xml";
$header[] = "Content-length: ".strlen($request) . "\r\n";
$header[] = $request;

$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, "http://www.champions-online.com/xmlrpc.php"); # URL to post to
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); # return into a variable
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header ); # custom headers, see above
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' ); # This POST is special, and uses its specified Content-type
$result = curl_exec( $ch ); # run!
curl_close($ch); 

echo $result;
?>

But I'm getting a "400 Bad Request" error. I'm new to XML RPC and I barely know php, so I'm at a loss. The examples from the php site show how to use an array as a parameter, but nothing else.

I obtained the parameter string <param><value><string>en-US</string></value></param> from this XMLRPC Debugger (very nice btw). I entered the parameter I needed in the "payload" box and this was the output.

So, I would appreciate any help on how to pass this parameter to the header.

Note: My host supports xmlrpc but it seems the function "xmlrpc_client" doesn't exist.


Update: The web master replied with this information, but it's still not working... it's getting to the point I may just scrape the status off the page.

$request = xmlrpc_encode_request("wgsLauncher.getServerStatus", "en-US" );

© Stack Overflow or respective owner

Related posts about xmlrpc

Related posts about curl