XML_RPC2是否支持cookie?

时间:2011-01-27 12:45:26

标签: php cookies xml-rpc pear

我正在开发一个XMLRPC客户端,它必须支持cookie进行身份验证。如何获取响应cookie并使用XML RPC2设置请求cookie?

3 个答案:

答案 0 :(得分:2)

我假设您使用的是PHP / PEAR

从版本1.1.0b1开始,程序包使用HTTP_Request2

创建HTTP_Request2并将其传递给XML_RPC作为选项参数以使用cookie:

 <?php
 //Include the PEAR packages
 require_once 'XML/RPC2/Client.php';
 require_once 'HTTP/Request2.php';

 //Create the HTTP_Request2 object and add your cookie details
 $http_request = new HTTP_Request2();
 $http_request2->addCookie($name = 'myCookie', $value = 'myValue');

 //Create the XML_RPC2_Client
 $params = array('httpRequest'=>$http_request);
 $client = XML_RPC2_Client::create($url = 'http://www.example.com', $params);
 //do your stuff

 ?>

答案 1 :(得分:2)

XML_RPC2支持cookie,例如:

require_once 'XML/RPC2/Client.php';
require_once 'HTTP/Request2.php';
require_once 'HTTP/Request2/CookieJar.php';

$http_request = new HTTP_Request2();
$cookie = new HTTP_Request2_CookieJar();
$http_request->setCookieJar($cookie);

$options = array(
    'prefix' => 'prefix.',
    'httpRequest' => $http_request
);

$client = XML_RPC2_Client::create('http://api.host.com/xmlrpc/', $options);

$result = $client->login('LOGIN', 'PASSWORD');

var_dump($cookie);

$result = $client->get_info();

答案 2 :(得分:1)

XML_RPC2不支持Cookie