在标头中传递参数 (XML RPC)

发布于 2024-08-26 04:25:06 字数 2127 浏览 8 评论 0原文

我正在尝试为 MMORPG Champions Online 设置服务器状态。我从网络管理员那里得到了一些基本信息,这就是他告诉我的全部信息:

现在,我找到了一个很好的示例,以 这里,我最终得到了这段代码:

<?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:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他是夢罘是命 2024-09-02 04:25:07

好吧,我终于找到了我的答案......这似乎是标题中的问题,因为当我更改 cURL 代码以匹配我在 此网站。这篇文章是关于如何在 php 中使用 XMLRPC 远程发布到 wordpress。

这是我最终得到的代码:

<?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 . "<br>";
echo $notice;

?>

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:

<?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 . "<br>";
echo $notice;

?>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文