如何从 PHP 访问 XML-RPC 数据?

发布于 2024-10-29 13:35:46 字数 1274 浏览 3 评论 0原文

远程服务器正在通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漫漫岁月 2024-11-05 13:35:46

知道了!显然数据位于“$GLO​​BALS['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");
}

我还使用不同的库,来自:
http://www.keithdevens.com/software/xmlrpc/source.php

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文