在标头中传递参数 (XML RPC)
我正在尝试为 MMORPG Champions Online 设置服务器状态。我从网络管理员那里得到了一些基本信息,这就是他告诉我的全部信息:
- XML-RPC call to server: http://www.champions-online.com/xmlrpc.php
- 函数名称:wgsLauncher.getServerStatus
- 参数(语言):en-US
现在,我找到了一个很好的示例,以 这里,我最终得到了这段代码:
<?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) . "\r\n";
$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 Bad Request”错误。我是 XML RPC 的新手,而且我几乎不了解 php,所以我很茫然。 php 站点中的 示例 展示了如何使用一个数组作为参数,但没有别的。
我从此 XMLRPC 调试器(顺便说一句,非常好)。我在“有效负载”框中输入了所需的参数,这就是输出。
因此,我将不胜感激有关如何将此参数传递给标头的任何帮助。
注意:我的主机支持 xmlrpc 但似乎功能“xmlrpc_client”不存在。
更新:网站管理员回复了此信息,但它仍然不起作用......已经到了我可能只是从页面上删除状态的地步。
$request = xmlrpc_encode_request("wgsLauncher.getServerStatus", "en-US" );
I'm trying to set up a server status for the MMORPG Champions Online. I got some basic information from the web master and this is all he told me:
- XML-RPC call to server: http://www.champions-online.com/xmlrpc.php
- function name: wgsLauncher.getServerStatus
- Parameter (language): en-US
Now, I found a nice example to start with here, and I ended up with this code:
<?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) . "\r\n";
$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;
?>
But I'm getting a "400 Bad Request" error. I'm new to XML RPC and I barely know php, so I'm at a loss. The examples from the php site show how to use an array as a parameter, but nothing else.
I obtained the parameter string <param><value><string>en-US</string></value></param>
from this XMLRPC Debugger (very nice btw). I entered the parameter I needed in the "payload" box and this was the output.
So, I would appreciate any help on how to pass this parameter to the header.
Note: My host supports xmlrpc but it seems the function "xmlrpc_client" doesn't exist.
Update: The web master replied with this information, but it's still not working... it's getting to the point I may just scrape the status off the page.
$request = xmlrpc_encode_request("wgsLauncher.getServerStatus", "en-US" );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我终于找到了我的答案......这似乎是标题中的问题,因为当我更改 cURL 代码以匹配我在 此网站。这篇文章是关于如何在 php 中使用 XMLRPC 远程发布到 wordpress。
这是我最终得到的代码:
Ok, I finally figured out my answer... It seemed to be a problem in the header, because it worked when I changed the cURL code to match the code I found it on this site. The post is about how to remotely post to wordpress using XMLRPC in php.
This is the code I ended up with: