需要 php 中 xmlrpc 的帮助
我已经从 http://phpxmlrpc.sourceforge.net/ 下载了 phpxmlrpc
我的网络服务器上有一个名为xmlrpc-test 并创建了一个简单的测试 php 应用程序。
<?php
include 'xmlrpc.inc';
include 'xmlrpcs.inc';
function sumAndDifference ($params) {
// Parse our parameters.
$xval = $params->getParam(0);
$x = $xval->scalarval();
$yval = $params->getParam(1);
$y = $yval->scalarval();
// Build our response.
$struct = array('sum' => new xmlrpcval($x + $y, 'int'),
'difference' => new xmlrpcval($x - $y, 'int'));
return new xmlrpcresp(new xmlrpcval($struct, 'struct'));
}
// Declare our signature and provide some documentation.
// (The PHP server supports remote introspection. Nifty!)
$sumAndDifference_sig = array(array('struct', 'int', 'int'));
$sumAndDifference_doc = 'Add and subtract two numbers';
new xmlrpc_server(array('sample.sumAndDifference' =>
array('function' => 'sumAndDifference',
'signature' => $sumAndDifference_sig,
'docstring' => $sumAndDifference_doc)));
?>
我已经加载了 phpxmlrpc 调试器,输入了地址:、端口:和路径:但是当我按下 列出可用方法
的执行按钮时,没有任何反应。
问题 1:为什么我的本地调试器无法工作?
所以我在这里上网 http://phpxmlrpc.sourceforge.net/jsxmlrpc/debugger/debugger .html 似乎效果更好。
但是,当我按下此处的执行按钮(输入服务器详细信息后)时,我收到以下消息。
故障代码:[5] 原因:“未从远程服务器接收到 200 OK。 (发送失败)'
我认为这可能意味着我的本地服务器和 WAN 出现问题,因此我在 http 上测试了该应用程序://feedvalidator.org/ 事实上我确实得到了回复。
1. <?xml version="1.0"?>
2. <methodResponse>
3. <fault>
4. <value>
5. <struct><member><name>faultCode</name>
6. <value><int>105</int></value>
7. </member>
8. <member>
9. <name>faultString</name>
10. <value><string>XML error: Invalid document end at line 1, column 1</string></value>
11. </member>
12. </struct>
13. </value>
14. </fault>
15. </methodResponse>
我认为这是一个错误,因为没有发送有效负载。
问题 2:我该如何解决这个问题?我怎样才能得到一个非常简单的 xmlrpc 服务器与 php 一起工作?
I have downloaded phpxmlrpc from http://phpxmlrpc.sourceforge.net/
I have a folder on my webserver called xmlrpc-test and have a simple test php app created.
<?php
include 'xmlrpc.inc';
include 'xmlrpcs.inc';
function sumAndDifference ($params) {
// Parse our parameters.
$xval = $params->getParam(0);
$x = $xval->scalarval();
$yval = $params->getParam(1);
$y = $yval->scalarval();
// Build our response.
$struct = array('sum' => new xmlrpcval($x + $y, 'int'),
'difference' => new xmlrpcval($x - $y, 'int'));
return new xmlrpcresp(new xmlrpcval($struct, 'struct'));
}
// Declare our signature and provide some documentation.
// (The PHP server supports remote introspection. Nifty!)
$sumAndDifference_sig = array(array('struct', 'int', 'int'));
$sumAndDifference_doc = 'Add and subtract two numbers';
new xmlrpc_server(array('sample.sumAndDifference' =>
array('function' => 'sumAndDifference',
'signature' => $sumAndDifference_sig,
'docstring' => $sumAndDifference_doc)));
?>
I have loaded the phpxmlrpc debugger, entered the Address:, Port: and Path: but when I press the execute button for List available methods
nothing happens.
Question 1: why does my local debugger not work?
So I went online here http://phpxmlrpc.sourceforge.net/jsxmlrpc/debugger/debugger.html and it seems to work better.
However, when I press the execute button here (after entering my server details) I get the following message.
Fault code: [5] Reason: 'Didn't receive 200 OK from remote server. (send failed)'
I thought this may have meant there was something wrong with my local server and the WAN so I tested the app at http://feedvalidator.org/ and I do in fact get a response.
1. <?xml version="1.0"?>
2. <methodResponse>
3. <fault>
4. <value>
5. <struct><member><name>faultCode</name>
6. <value><int>105</int></value>
7. </member>
8. <member>
9. <name>faultString</name>
10. <value><string>XML error: Invalid document end at line 1, column 1</string></value>
11. </member>
12. </struct>
13. </value>
14. </fault>
15. </methodResponse>
I think this is an error because there is not payload being sent.
Question 2: How do I solve this? How can I get a very simple xmlrpc server working with php?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了后代,我将提供我的意见。
第一的,
由于安全沙箱的无声破坏,您的本地调试器无法工作。 W3C 和浏览器供应商制定了一个方案,浏览器将默默地将调试器发送的 POST 请求转换为 OPTION 请求。这看起来像是一个真正的拼凑,因为浏览器没有给出任何明显的迹象表明它正在这样做,但这是标准行为。如果您进入 Firebug 或控制台并查看网络流量,您将亲眼目睹。
第二,
该示例看起来像是有关 Joomla 的“Master...”一书中的示例。技术堆栈中任何地方的众多缺陷和配置设置都可能成为障碍。我今天刚刚遇到了同样的问题。这里真正要学到的教训是“不要这样做”。使用具有更好的工具链支持和更直接的成功之路的开发环境。
For posterity, I'll give my input.
First,
Your local debugger doesn't work because of silent sabotaging by the security sandbox. The W3C and browser vendors worked out a scheme whereby the browser will silently translate the POST request your debugger is sending to an OPTION request instead. It seems like a real kludge because the browser gives no visible indication that it is doing this, but it is standard behavior. If you go into Firebug or the console and look at the network traffic you'll see it first hand.
Second,
That example looks like the one from the "Master..." book about Joomla. Could well be that any of numerous flaws and configuration settings anywhere along the technology stack could be the roadblock. I just ran into the same issue today. The real lesson to learn here is, "don't do that". Use a development environment that has better tool chain support and a more straightforward path to success.
很抱歉给您带来不好的体验。
对于后代:
我测试了您的代码,逐字复制粘贴,并且它有效。
您的调试器问题很可能是由于网络/php 配置造成的。
答:正如 @jerseyboy 所回答的,sf.net 上的公共 javascript 调试器基于 JS 技术构建,只能将 xmlrpc 请求发送到托管它的同一域。或者,您需要在自己的服务器中添加对 CORS 请求的支持。
请注意,我已经更新了 js 调试器以显示有关此问题的信息。
B. 有一个公共 xmlrpc 调试器,位于 https://gggeek.altervista.org/sw /xmlrpc/debugger/ ,它是用 PHP 编写的,因此它在连接到远程服务器时不受任何限制。建议使用这个而不是js。
层上的问题很有用
C. 所有 3 个调试器(公共 php 一个、本地 php 一个、公共 js 一个)都有一个“显示更多信息”选择器,这对于让它们转储尽可能多的信息以解决 http调用 使用浏览器进行调试:如果您尝试使用浏览器访问 xmlrpc 服务器的 url,您应该得到包含 xml 内容的“500 错误”页面作为响应。如果你得到一个空白页,则意味着你有一个 php 致命错误。要对其进行故障排除,请在 php.ini 中设置
display_errors=true
,和/或检查网络服务器的错误日志E。当点击“执行”按钮时,本地 php 调试器不执行任何操作,这很奇怪。我能想到的是,由于 JS 错误,表单没有提交。要解决这些问题,请使用浏览器的开发人员工具 js 控制台
回到原来的问题:
Q1 - 参见 E 点
Q2 - 参见 B、C、D、E 点
Sorry about the bad experience.
For posterity:
I tested your code, verbatim copy-pasted, and it works.
Your problems with the debugger are most likely due to networking / php configuration.
A. as answered by @jerseyboy, the the public javascript debugger at sf.net, being built on JS technology, can only send xmlrpc requests to the same domain hosting it. Either that, or you need to add to your own server support for CORS requests.
Note that I have updated the js debugger to show info about this issue.
B. there is a public xmlrpc debugger available at https://gggeek.altervista.org/sw/xmlrpc/debugger/ , which is written in PHP, and as such it does not suffer any limitations in connecting to remote servers. It is recommended to use this one over the js one.
C. all 3 debuggers (public php one, local php one, public js one) have a "show more info" selector, that is useful to make them dump as much information as possible to troubleshoot the issue on the http-call layer
D. debugging with a browser: if you try to access your xmlrpc server's url with a browser, you should get as response a '500 error' page with xml contents. If you get a blank page it means that you have a php fatal error. To troubleshoot it, set
display_errors=true
in php.ini, and/or check the webserver's error logE. it is quite weird that the local php debugger does nothing when hitting the "execute" button. All I can think of is that the form does not get submitted because of JS errors. To troubleshoot those, use the browser's developer's tools js console
Back to the original questions:
Q1 - see point E
Q2 - see points B, C, D, E