首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PEAR XML_RPC_encode vs PHP xmlrpc_encode_request

PEAR XML_RPC_encode vs PHP xmlrpc_encode_request
EN

Stack Overflow用户
提问于 2012-01-18 03:03:34
回答 1查看 1.2K关注 0票数 0

我正在探索使用XMLRPC服务在Drupal系统和我们网站的另一部分之间进行通信。我找到了一些PHP的php_xmlrpc扩展的示例代码,但发现我们的web主机不支持该扩展。

相反,它们提供PEAR XML_RPC包

这两种方法的编码似乎有很大的不同。

我用来设置请求的PHP代码,基于http://drupal.org/node/339845

代码语言:javascript
复制
$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 )返回了我需要的内容,如下所示:

代码语言:javascript
复制
<?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()函数返回以下内容:

代码语言:javascript
复制
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的函数?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-01-18 03:46:10

该文档可从http://pear.php.net/manual/en/package.webservices.xml-rpc.api.php获得

要获得XML marshalled输出,首先要构造一条消息,然后使用->serialize()方法:

代码语言:javascript
复制
$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接口使用的,该接口处理原始数据转换。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8900179

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档