2017-02-11 89 views
2

有人可以幫我使用XML-RPC嗎? 我使用庫xmlrpc http://gggeek.github.io/phpxmlrpc/ 4.0.0版本PHP - XML RPC錯誤

我不知道如何調用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"); 

    } 


} 

Client類

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 

回答

0

的致命錯誤是在調度映射的定義:"function" => "getData"應該"function" => array($this, "getData")

否則,xmlrpc服務器將在接收xmlrpc調用時尋找全局php函數'getData'來執行,而不是尋找它自己的方法。

補充說明:在你的榜樣,你也應該解決return PhpXmlRpc\Response($myexport, "array");return new PhpXmlRpc\Response(new PhpXmlRpc\Value($myexport, "array"));