简体   繁体   English

在 php 中需要有关 xmlrpc 的帮助

[英]Need help with xmlrpc in php

I have downloaded phpxmlrpc from http://phpxmlrpc.sourceforge.net/我已经从http://phpxmlrpc.sourceforge.net/下载了 phpxmlrpc

I have a folder on my webserver called xmlrpc-test and have a simple test php app created.我的网络服务器上有一个名为 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)));
?>

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.我已经加载了 phpxmlrpc 调试器,输入了地址:、端口:和路径:但是当我按下用于List available methods的执行按钮时,没有任何反应。

Question 1 : why does my local debugger not work?问题 1 :为什么我的本地调试器不工作?

So I went online here http://phpxmlrpc.sourceforge.net/jsxmlrpc/debugger/debugger.html and it seems to work better.所以我在这里上网http://phpxmlrpc.sourceforge.net/jsxmlrpc/debugger/debugger.html它似乎工作得更好。

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.故障代码:[5] 原因:'未从远程服务器收到 200 OK。 (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.我认为这可能意味着我的本地服务器和 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>

I think this is an error because there is not payload being sent.我认为这是一个错误,因为没有发送有效负载。

Question 2: How do I solve this?问题2:我该如何解决这个问题? How can I get a very simple xmlrpc server working with php?我怎样才能得到一个非常简单的 xmlrpc 服务器与 php 一起工作?

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. W3C和浏览器供应商制定了一种方案,浏览器将以静默方式将调试器正在发送的POST请求转换为OPTION请求。 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. 如果您进入Firebug或控制台并查看网络流量,则将直接看到它。

Second, That example looks like the one from the "Master..." book about Joomla. 其次,该示例类似于《 Master ...》一书中有关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. 使用具有更好的工具链支持和更直接的成功之路的开发环境。

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.您的调试器问题很可能是由于网络/php 配置造成的。

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. A. 正如@jerseyboy 所回答的那样,sf.net 上的公共javascript调试器基于 JS 技术构建,只能将 xmlrpc 请求发送到托管它的同一域。 Either that, or you need to add to your own server support for CORS requests.要么,要么您需要向自己的服务器添加对 CORS 请求的支持。 Note that I have updated the js debugger to show info about this issue.请注意,我已经更新了 js 调试器以显示有关此问题的信息。

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. B. 在https://gggeek.altervista.org/sw/xmlrpc/debugger/有一个公共的 xmlrpc 调试器,它是用 PHP 编写的,因此它在连接到远程服务器时不受任何限制。 It is recommended to use this one over the js one.建议使用这个而不是 js 的。

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 C. 所有 3 个调试器(公共 php 一个,本地 php 一个,公共 js 一个)都有一个“显示更多信息”选择器,这有助于让它们转储尽可能多的信息以解决 http 调用层上的问题

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. D. 用浏览器调试:如果你试图用浏览器访问你的 xmlrpc 服务器的 url,你应该得到一个带有 xml 内容的“500 错误”页面作为响应。 If you get a blank page it means that you have a php fatal error.如果你得到一个空白页面,这意味着你有一个 php 致命错误。 To troubleshoot it, set display_errors=true in php.ini, and/or check the webserver's error log要排除故障,请在 php.ini 中设置display_errors=true ,和/或检查网络服务器的错误日志

E. it is quite weird that the local php debugger does nothing when hitting the "execute" button. E. 本地 php 调试器在点击“执行”按钮时什么都不做是很奇怪的。 All I can think of is that the form does not get submitted because of JS errors.我能想到的是,由于 JS 错误,表单没有提交。 To troubleshoot those, use the browser's developer's tools js console要解决这些问题,请使用浏览器的开发人员工具 js 控制台

Back to the original questions:回到最初的问题:

Q1 - see point E Q1 - 见 E 点

Q2 - see points B, C, D, E Q2 - 见 B、C、D、E 点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM