我正在探索使用XMLRPC服务在Drupal系统和我们网站的另一部分之间进行通信。我找到了一些PHP的php_xmlrpc扩展的示例代码,但发现我们的web主机不支持该扩展。
相反,它们提供PEAR XML_RPC包
这两种方法的编码似乎有很大的不同。
我用来设置请求的PHP代码,基于http://drupal.org/node/339845
$method_name = 'user.login';
$user_credentials = array(
0 => 'example.user',
1 => 'password',
);
// any user-defined arguments for this service
// here we use the login credentials we specified at the top of the script
$user_args = $user_credentials;
$required_args=array();
// add the arguments to the request
foreach ($user_args as $arg) {
array_push($required_args, $arg);
}
...then call the XMLRPC functions here...我在我的PC上测试了php_xmlrpc和WAMPserver,php_xmlrpc的function xmlrpc_encode_request ( http://us.php.net/manual/en/function.xmlrpc-encode-request.php )返回了我需要的内容,如下所示:
<?xml version="1.0" encoding="iso-8859-1"?>
<methodCall>
<methodName>user.login</methodName>
<params>
<param>
<value>
<string>example.user</string>
</value>
</param>
<param>
<value>
<string>password</string>
</value>
</param>
</params>
</methodCall>而PEAR XML_RPC_encode()函数返回以下内容:
Array
(
[0] => example.user
[1] => password
)
object(XML_RPC_Value)#1 (2) {
["me"]=>
array(1) {
["string"]=>
string(10) "user.login"
}
["mytype"]=>
int(1)
}PEAR中有没有另一个可以将参数编码成XML_RPC的函数?
发布于 2012-01-18 03:46:10
该文档可从http://pear.php.net/manual/en/package.webservices.xml-rpc.api.php获得
要获得XML marshalled输出,首先要构造一条消息,然后使用->serialize()方法:
$msg = new XML_RPC_Message("function", array(new XML_RPC_Value(123, "int")));
print $msg->serialize();您的XML_RPC_encode()函数旨在将一个普通的php数组包装到这样的XML_RPC_*对象中。
但显然,PEAR类主要是通过XML_RPC_Client接口使用的,该接口处理原始数据转换。
https://stackoverflow.com/questions/8900179
复制相似问题