快速业务通道

PHP xml-rpc远程调用

作者 佚名技术 来源 NET编程 浏览 发布时间 2012-05-25
k;
}
}
}else{
$temp = (string)$current_node;
}
return $temp;
}
function XMLRPC_getParams($request){
if(!is_array($request[''methodCall''][''params''])){
#If there are no parameters, return an emptyempty array
return array();
}else{
#echo "Getting rid of methodCall -> params -> param<br>\n";
$temp = $request[''methodCall''][''params''][''param''];
if(is_array($temp) and array_key_exists(0, $temp)){
$count = count($temp);
for($n = 0; $n < $count; $n++){
#echo "Serializing parameter $n<br>";
$temp2[$n] = &XMLRPC_adjustValue($temp[$n][''value'']);
}
}else{
$temp2[0] = &XMLRPC_adjustValue($temp[''value'']);
}
$temp = $temp2;
return $temp;
}
}
function XMLRPC_getMethodName($methodCall){
#returns the method name
return $methodCall[''methodCall''][''methodName''];
}
function XMLRPC_request($site, $location, $methodName, $params = NULL, $user_agent = NULL){
$site = explode('':'', $site);
if(isset($site[1]) and is_numeric($site[1])){
$port = $site[1];
}else{
$port = 80;
}
$site = $site[0];
$data["methodCall"]["methodName"] = $methodName;
$param_count = count($params);
if(!$param_count){
$data["methodCall"]["params"] = NULL;
}else{
for($n = 0; $n<$param_count; $n++){
$data["methodCall"]["params"]["param"][$n]["value"] = $params[$n];
}
}
$data = XML_serialize($data);
if(defined(''XMLRPC_DEBUG'') and XMLRPC_DEBUG){
XMLRPC_debug(''XMLRPC_request'', "<p>Received the following parameter list to send:</p>" . XMLRPC_show($params, ''print_r'', true));
}
$conn = fsockopen ($site, $port); #open the connection
if(!$conn){ #if the connection was not opened successfully
if(defined(''XMLRPC_DEBUG'') and XMLRPC_DEBUG){
XMLRPC_debug(''XMLRPC_request'', "<p>Connection failed: Couldn''t make the connection to $site.</p>");
}
return array(false, array(''faultCode''=>10532, ''faultString''=>"Connection failed: Couldn''t make the connection to $site."));
}else{
$headers =
"POST $location HTTP/1.0\r\n" .
"Host: $site\r\n" .
"Connection: close\r\n" .
($user_agent ? "User-Agent: $user_agent\r\n" : '''') .
"Content-Type: text/xml\r\n" .
"Content-Length: " . strlen($data) . "\r\n\r\n";
fputs($conn, "$headers");
fputs($conn, $data);
if(defined(''XMLRPC_DEBUG'') and XMLRPC_DEBUG){
XMLRPC_debug(''XMLRPC_request'', "<p>Sent the following request:</p>\n\n" . XMLRPC_show($headers . $data, ''print_r'', true));
}
#socket_set_blocking ($conn, false);
$response = "";
while(!feof($conn)){
$response .= fgets($conn, 1024);
}
fclose($conn);
#strip headers off of response
$data = XML_unserialize(substr($response, strpos($response, "\r\n\r\n")+4));
if(defined(''XMLRPC_DEBUG'') and XMLRPC_DEBUG){
XMLRPC_debug(''XMLRPC_request'', "<p>Received the following response:</p>\n\n" . XMLRPC_show($response, ''print_r'', true) . "<p>Which was serialized into the following data:</p>\n\n" . XMLRPC_show($data, ''print_r'', true));
}
if(isset($data[''methodResponse''][''fault''])){
$return = array(false, XMLRPC_adjustValue($data[''methodResponse''][''fault''][''value'']));
if(defined(''XMLRPC_DEBUG''

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号