Passing a parameter in the header (XML RPC)
我正在尝试为MMORPG Champions Online设置服务器状态。我从网络管理员那里获得了一些基本信息,这就是他告诉我的一切:
- 对服务器的XML-RPC调用:http://www.champions-online.com/xmlrpc.php
- 函数名称:wgsLauncher.getServerStatus
- 参数(语言):zh-CN
现在,我找到了一个很好的示例,从这里开始,最后我得到了以下代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <?php ini_set('display_errors', 1); error_reporting(E_ALL); # Using the XML-RPC extension to format the XML package $request = xmlrpc_encode_request("wgsLauncher.getServerStatus","<param><value><string>en-US</string></value></param>", null ); # Using the cURL extension to send it off, # first creating a custom header block $header[] ="Host: http://www.champions-online.com:80/"; $header[] ="Content-type: text/xml"; $header[] ="Content-length:".strlen($request) ."\ \ "; $header[] = $request; $ch = curl_init(); curl_setopt( $ch, CURLOPT_URL,"http://www.champions-online.com/xmlrpc.php"); # URL to post to curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); # return into a variable curl_setopt( $ch, CURLOPT_HTTPHEADER, $header ); # custom headers, see above curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' ); # This POST is special, and uses its specified Content-type $result = curl_exec( $ch ); # run! curl_close($ch); echo $result; ?> |
但是我收到一个" 400错误请求"错误。我是XML RPC的新手,我几乎不了解php,所以我很茫然。 php站点中的示例显示了如何使用数组作为参数,但仅此而已。
我从此XMLRPC调试器(非常不错)获得了参数字符串
因此,对于如何将此参数传递到标头,我将不胜感激。
注意:我的主机支持xmlrpc,但是功能" xmlrpc_client "似乎不存在。
更新:网站管理员回答了此信息,但是仍然无法正常工作...到了要点,我可能只是将状态从页面上删除了。
1 |
好吧,我终于想出了答案...标题似乎是个问题,因为当我更改cURL代码以匹配在此站点上找到的代码时,它可以工作。该帖子是关于如何在php中使用XMLRPC远程发布到wordpress的。
这是我最后得到的代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | <?php // ini_set('display_errors', 1); // error_reporting(E_ALL); # Using the XML-RPC extension to format the XML package $request = xmlrpc_encode_request("wgsLauncher.getServerStatus","en-US" ); $ch = curl_init(); curl_setopt($ch, CURLOPT_POSTFIELDS, $request); curl_setopt($ch, CURLOPT_URL,"http://www.champions-online.com/xmlrpc.php"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 1); $result = curl_exec($ch); curl_close($ch); $method = null; $params = xmlrpc_decode_request($result, &$method); # server status result = true (up) or false (down) $status = ($params['status']) ? 'up' : 'down'; $notice = ($params['notice'] =="") ?"" :"Notice:" + $params['notice']; echo"Server Status:" . $status .""; echo $notice; ?> |