PHP - XML RPC错误

时间:2017-02-11 14:12:32

标签: php xml rpc

有人可以帮我使用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

1 个答案:

答案 0 :(得分:0)

致命错误出现在发货地图的定义中:"function" => "getData"应为"function" => array( $this, "getData")

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

作为旁注:在您的示例中,您还应将return PhpXmlRpc\Response( $myexport, "array" );修改为return new PhpXmlRpc\Response( new PhpXmlRpc\Value( $myexport, "array" ) );