如何从 PHP 访问 XML-RPC 数据?
远程服务器正在通过 RPC 将 XML 发布到我的服务器。当我打开 mod 安全性时,我可以在 Apache 日志中看到 XML,但无法从 PHP 脚本访问 XML。它应该是一个 POST 请求,但 $_POST 数组为空。
我的理解是 RPC 应该用数据调用我的函数,但这似乎没有发生。
这个极其简单的脚本应该将 XML 写入日志文件,但它什么也不做:
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") ) );
他们向我发送了这样的信息:
<?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>
....
为什么我的函数没有被调用?!?
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?!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
知道了!显然数据位于“$GLOBALS['HTTP_RAW_POST_DATA']”中。
我还使用不同的库,来自:
http://www.keithdevens.com/software/xmlrpc/source.php
Got it! Apparently the data is in "$GLOBALS['HTTP_RAW_POST_DATA']".
I'm also using a differnt library, from:
http://www.keithdevens.com/software/xmlrpc/source.php