【问题标题】:PHP - XML RPC errorPHP - XML RPC 错误
【发布时间】:2017-06-29 19:59:44
【问题描述】:

有人可以帮助我处理 XML - RPC 吗? 我使用库 xmlrpc http://gggeek.github.io/phpxmlrpc/ 版本 4.0.0

我不知道如何调用 getData 并进入结果。 我经常返回错误 17

谢谢大家!!

这是我的“服务器”类。

class xmlrpc_server (

    public function run(){

            $this->getMethods();
            $this->server = new PhpXmlRpc\Server($this->methods);

    }


    public function getMethods(){

            $this->methods = array(

                "getData" => array(
                    "function" => "getData",
                    "signature" => array( array( PhpXmlRpc\Value::$xmlrpcArray, PhpXmlRpc\Value::$xmlrpcInt   )),
                    "docstring" => "Auth server - getData (with AUTH ID)." 
                )          

            );

    } 



    function getData($m){

            $mydata = array();
            $mydata['user_id'] = $m->getParam(0); //sended user ID

            return PhpXmlRpc\Response( $myexport, "array" );

    }


}

客户端类

class client( 

  public function send(){

                  $this->user_id      = 123456;

                  PhpXmlRpc\PhpXmlRpc::$xmlrpc_internalencoding = 'UTF-8';
                  $this->server_connect = new xmlrpc_client('/index.php', 'myserver.com', 80);

                  $params         = array(new xmlrpcval($this->user_id, 'int'));
                  $msg            = new xmlrpcmsg('getData', $params); //call 'getData'
                  $response       = $this->server_connect->send($msg);  //send and get response

                  print_r($response);  //print response

  }

)

$client = new client;
$client->send();

以及 print_r() 的结果

PhpXmlRpc\Response Object
(
    [val] => 0
    [valtyp] => 
    [errno] => 17
    [errstr] => Internal server error: no function matches method
    [payload] => 
    [hdrs] => Array
        (
            [date] => Sat, 11 Feb 2017 13:57:40 GMT
            [server] => Apache/2.4.10 (Debian)
            [vary] => Accept-Charset,Accept-Encoding
            [content-encoding] => gzip
            [content-length] => 201
            [connection] => close
            [content-type] => text/xml; charset=UTF-8
        )

    [_cookies] => Array
        (
        )

    [content_type] => text/xml
    [raw_data] => HTTP/1.1 200 OK
Date: Sat, 11 Feb 2017 13:57:40 GMT
Server: Apache/2.4.10 (Debian)
Vary: Accept-Charset,Accept-Encoding
Content-Encoding: gzip
Content-Length: 201
Connection: close
Content-Type: text/xml; charset=UTF-8

【问题讨论】:

    标签: php xml rpc


    【解决方案1】:

    致命错误在调度映射的定义中:"function" => "getData" 应该是"function" => array( $this, "getData")

    否则 xmlrpc 服务器将在接收 xmlrpc 调用时寻找全局 php 函数“getData”来执行,而不是寻找自己的方法。

    附带说明:在您的示例中,您还应该将 return PhpXmlRpc\Response( $myexport, "array" ); 修复为 return new PhpXmlRpc\Response( new PhpXmlRpc\Value( $myexport, "array" ) );

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-12
      • 1970-01-01
      • 2010-11-07
      • 1970-01-01
      • 2015-09-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多