如何在 PHP 中在 localhost 上实现 xml_rpc 客户端?
你好,我在用 PHP 编写一个简单的 XML-RPC 客户端时遇到一些问题。 这是我的 PHP 代码:
$site_name = "Mikangali";
$site_url = "http://www.mikangali.com";
$site_url = "http://localhost";
$request = xmlrpc_encode_request("weblogUpdates.ping", array($site_name, $site_url));
#echo $request;
$http_request = array(
'method' => "POST",
'header' => "Content-Type: text/xml\r\nUser-Agent: PHPRPC/1.0\r\nHost: rpc.technorati.com\r\n",
'content' => $request
);
#print_r($http_request) ;
$context = stream_context_create(array('http' => $http_request));
$file = @file_get_contents($server_url, false, $context);
if ($file==false) {
#handle error here...
display_mssg("error","! we get a pb !");
}
$response = xmlrpc_decode($file);
if (is_array($response) and xmlrpc_is_fault($response)){
display_mssg("error","Failed to ping ".$site_name);
}
else {
display_mssg("success","Successfully pinged ".$site_name);
var_dump($response);
var_dump($file);
}
我不明白为什么它进入“成功”条件并向我显示:
! we get a pb !
Successfully pinged Technorati
null
boolean false
感谢您的帮助。 请注意,XML-RPC PHP 扩展在我的本地 wamp 服务器上已激活。
Hello i have somme problems to write a simple XML-RPC client in PHP.
This is my PHP code:
$site_name = "Mikangali";
$site_url = "http://www.mikangali.com";
$site_url = "http://localhost";
$request = xmlrpc_encode_request("weblogUpdates.ping", array($site_name, $site_url));
#echo $request;
$http_request = array(
'method' => "POST",
'header' => "Content-Type: text/xml\r\nUser-Agent: PHPRPC/1.0\r\nHost: rpc.technorati.com\r\n",
'content' => $request
);
#print_r($http_request) ;
$context = stream_context_create(array('http' => $http_request));
$file = @file_get_contents($server_url, false, $context);
if ($file==false) {
#handle error here...
display_mssg("error","! we get a pb !");
}
$response = xmlrpc_decode($file);
if (is_array($response) and xmlrpc_is_fault($response)){
display_mssg("error","Failed to ping ".$site_name);
}
else {
display_mssg("success","Successfully pinged ".$site_name);
var_dump($response);
var_dump($file);
}
I can't figure out why it enter on the "success" condition and display me that:
! we get a pb !
Successfully pinged Technorati
null
boolean false
Thanks for you help.
Notice that XML-RPC PHP extention is activated, on my local wamp server.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然是因为
xmlrpc_decode(false)
返回null
$file = false
,因为你有问题。 (=> !
我们得到一个 pb!
)所以你不会进入检查
$response
是否是一个数组的 if 。Surely because
xmlrpc_decode(false)
is returningnull
$file = false
, cause you have a problem. (=> !
we get a pb!
)So you don't get into the if which is checking that
$response
is an array.