2011-01-27 83 views

回答

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 

?> 
2

XML_RPC2支持餅乾,例如:

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();