note 85462 modified in function.xmlrpc-encode-request by thiago
| From: | thiago@php.net | Date: | Fri, 24 Apr 2009 12:21:51 +0000 |
| Subject: | note 85462 modified in function.xmlrpc-encode-request by thiago | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-153657@lists.php.net to get a copy of this message | ||
The example above is incorrect - the header needs to be an array, see post by "chris dot
vigelius at gmx dot net": http://au.php.net/manual/en/function.stream-context-create.php#74431
His post also shows how to do browser authentication, as below:
<?php
$request = xmlrpc_encode_request("methodName", array("methodParam"));
$auth = base64_encode($username.":".$password);
$header = (version_compare(phpversion(), '5.2.8'))
? array("Content-Type: text/xml","Authorization: Basic $auth")
: "Content-Type: text/xml\r\nAuthorization: Basic $auth" ; //[1]
$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => $header,
'content' => $request
)));
$webservice="http://www.example.com/rpc";
$file = file_get_contents($webservice, false, $context);
$response = xmlrpc_decode($file);
if (xmlrpc_is_fault($response)) {
return "xmlrpc: $response[faultString] ($response[faultCode])";
} else {
return $response;
}
?>
1 - EDITOR NOTE: THIS IS A FIX FROM "SandersWang dt php at gmail dot com"
--was--
The example above is incorrect - the header needs to be an array, see post by "chris dot
vigelius at gmx dot net": http://au.php.net/manual/en/function.stream-context-create.php#74431
His post also shows how to do browser authentication, as below:
<?php
$request = xmlrpc_encode_request("methodName", array("methodParam"));
$auth = base64_encode($username.":".$password);
$header = array("Content-Type: text/xml","Authorization: Basic $auth");
$context = stream_context_create(array('http' => array(
'method' => "POST",
'header' => $header,
'content' => $request
)));
$webservice="http://www.example.com/rpc";
$file = file_get_contents($webservice, false, $context);
$response = xmlrpc_decode($file);
if (xmlrpc_is_fault($response)) {
return "xmlrpc: $response[faultString] ($response[faultCode])";
} else {
return $response;
}
?>
http://php.net/manual/en/function.xmlrpc-encode-request.php