Subject: | RPC Client to PHP 5.5.14 xml-rpc server 'parse-level-error'. |
When using the attached client.pl to call the "hello" method on "index.php" (running under PHP 5.5.14) I get:
$VAR1 = 'RPC::XML::Client::send_request: parse-level error: End-of-parse error: No error, methodCall or methodResponse detected';
...as the response.
This XML-RPC server, though, responds correctly to another XML-RPC client written with the Nwc XML RPC Client in C#.
Here is a sample output:
[Wed Dec 03 21:40:50.552289 2014] [:error] [pid 908] [client 127.0.0.1:49916] <?xml version="1.0" encoding="us-ascii"?><methodCall><methodName>hello</methodName><params></params></methodCall>
[Wed Dec 03 21:42:55.918132 2014] [:error] [pid 1205] [client 127.0.0.1:49928] <?xml version="1.0" encoding="utf-8"?><methodCall><methodName>hello</methodName><params><param><value><struct /></value></param></params></methodCall>
The first one, encoding in us-ascii is RPC::XML and it gets a response it cannot understand. The second one is generated by C# / Nwc classes.
Subject: | client.pl |
#!/usr/bin/perl
use strict;
use warnings;
use feature ':5.10';
use Carp;
use Data::Dumper;
use RPC::XML;
use RPC::XML::Client;
use Scalar::Util qw/blessed/;
BEGIN {
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
$ENV{PERL_LWP_USER_HTTP_10} ||= 1;
}
my $client = RPC::XML::Client->new("http://localhost/xml/index.php");
my $req = RPC::XML::request->new("hello");
say $req->as_string();
my $response = $client->send_request($req);
use Data::Dumper;
say Dumper($response);
Subject: | index.php |
<?php
###################### No user serviceable parts below #####################
#
# The XMLRPC server object
#
$xmlrpc_server = xmlrpc_server_create();
xmlrpc_server_register_method($xmlrpc_server, "hello", "hello");
function hello($method_name, $params, $app_data)
{
$response_xml = xmlrpc_encode(array('success' => true, '2' => '3'));
header("Content-type: text/xml");
echo $response_xml;
return "";
}
xmlrpc_server_register_method($xmlrpc_server, "reverse", "reverse");
function reverse($method_name, $params, $app_data) {
$request = $params[0];
$result = '';
if (isset($request['string'])) {
$result = strrev($request['string']);
}
$response_xml = xmlrpc_encode(array('success' => true, 'result' => $result));
header("Content-type: text/xml");
echo $response_xml;
return "";
}
#
# Process XMLRPC request
#
$request_xml = $HTTP_RAW_POST_DATA;
error_log($request_xml);
xmlrpc_server_call_method($xmlrpc_server, $request_xml, '');
xmlrpc_server_destroy($xmlrpc_server);
?>
Subject: | send.php |
<?php
$request = xmlrpc_encode_request("hello", array());
print "\n$request\n";