php - XMLRPC 显示 -32601 错误(使用 PHP)

标签 php web-services xml-rpc xmlrpclib xmlrpcclient

我有以下代码...

<?php
include("lib/xmlrpc.inc");

$email='<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="73041b120716051601331b1c071e121a1f5d101c1e" rel="noreferrer noopener nofollow">[email protected]</a>';

$c=new xmlrpc_client("/register/index.php", "ws.myserver.com", 80);
$f=new xmlrpcmsg('existsEmail', array(new xmlrpcval($email, "base64")));
print "<pre>" . htmlentities($f->serialize( )) . "</pre>";

$r=$c->send($f);
$v=$r->value( );

if (!$r->faultCode( )) {
    print "Email is". $email . " is " .
          $v->scalarval( ) . "<br />";
          print "<hr />I got this value back<br /><pre>" .
          htmlentities($r->serialize( )). "</pre><hr />\n";
} else {
    print "Fault: ";
    print "Code: " . $r->faultCode( ) .
    " Reason '" .$r->faultString( )."'<br />";
}

?>

我需要使用位于 http://ws.myserver.com/register/index.php 的 WebService .

我将电子邮件作为参数传递,然后 XMLRPC.inc 库将使用 base64 对其进行编码。

我有一个很好的 XML 请求,如下所示:

<?xml version="1.0"?>
<methodCall>
<methodName>existsEmail</methodName>
<params>
<param>
<value><base64>dnJvZHJpZ3VlekBpY2NrLm5ldC5jbw==</base64></value>
</param>
</params>
</methodCall>

BUUUT,当我尝试从服务器获取响应时,出现以下错误

故障:代码:-32601 原因“服务器错误。找不到请求的方法'

有什么想法吗?我对如何从我的 PHP 代码中调用 existsEmail 方法感到疯狂......我确信它在那里,但我不知道我是否遗漏了一些东西......

最佳答案

您将获得 error message (Specification for Fault Code Interoperability, version 20010516)来自您正在通信的 XMLRPC 端点。

这是一个定义的错误代码:

-32601 ---> server error. requested method not found

服务器未找到您请求的 RPC 方法。请联系您所使用的服务的支持人员以获取所有可用方法的列表。如果该方法可用,请联系支持人员并与他们讨论该问题。

您在评论中提问:

Is there any way [to] verify which methods are available?

这取决于服务。 sourceforge 上的 XMLRPC 有一个已定义方法的建议,您可以调用它来列出有关可用函数的信息:

XML-RPC Introspection

  • system.listMethods
  • system.methodSignature
  • system.methodHelp

您可以尝试一下它是否也适用于您的服务。据我所知,这些很常见,我总结了一个简单的示例,您可以在下面找到完整的代码。另请参阅代码下方的输出。

$path = 'http://xmlrpc-c.sourceforge.net/api/sample.php';

printf("\n XMLRPC Service Discovery\n\n for: '%s'\n\n", $path);

$discovery = new Discovery($path);
$methods = $discovery->getMethods();

printf(" Method Summary:\n ===============\n", count($methods));
foreach ($methods as $i => $method)
{
    printf(" %'.-2d %s\n", $i + 1, $method->getName());
}

printf("\n Method Details (%d):\n ===================\n", count($methods));
foreach ($methods as $i => $method)
{
    printf("  %'.-2d %s\n", $i + 1, $method->getName());
    printf("\n       %s\n", $method);
    printf("\n%s\n\n", preg_replace('/^/um', '     ', wordwrap($method->getHelp(), 46)));
}

输出:

 XMLRPC Service Discovery

 for: 'http://xmlrpc-c.sourceforge.net/api/sample.php'

 Method Summary:
 ===============
 1. debug.authInfo
 2. sample.add
 3. sample.sumAndDifference
 4. system.listMethods
 5. system.methodHelp
 6. system.methodSignature

 Method Details (6):
 ===================
  1. debug.authInfo

       <struct> debug.authInfo

     Report any HTTP authentication in use

  2. sample.add

       <int> sample.add (<int>, <int>)

     Add two numbers

  3. sample.sumAndDifference

       <struct> sample.sumAndDifference (<int>, <int>)

     Add and subtract two numbers

  4. system.listMethods

       <array> system.listMethods (<string>)

     This method lists all the methods that the
     XML-RPC server knows how to dispatch

  5. system.methodHelp

       <string> system.methodHelp (<string>)

     Returns help text if defined for the method
     passed, otherwise returns an empty string

  6. system.methodSignature

       <array> system.methodSignature (<string>)

     Returns an array of known signatures (an array
     of arrays) for the method name passed. If no
     signatures are known, returns a none-array
     (test for type != array to detect missing
     signature)

您可以在这里找到源代码:XMLRPC Discovery Service

关于php - XMLRPC 显示 -32601 错误(使用 PHP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9485085/

相关文章:

python - 将 Python xmlrpclib 与 unix 域套接字一起使用?

wordpress - 通过 XML RPC 获取 slug 的帖子

php - 在 WordPress 帖子中指定自定义规范 URL

javascript - 网站php链接末尾添加 "?"是什么意思?

PHPmailer 发送 HTML 代码

php - 按照他们发送或接收的最新消息的顺序选择人员

java - tomcat 6如何选择部署WAR文件的顺序

web-services - 具有特殊字符和 Xauthfile 的 wsimport

c# - Jquery 延迟函数调用

c# - XMLRPC c# 客户端到 python 客户端 - 方法不存在