得到";错误“=>";数组“;python JSON服务器和PHP客户端的数组响应


Getting "error"=>"Array" array response from python JSON server and PHP client

我用python编写了一个简单的JSON RPC服务器,作为python程序的接口。当我使用curl从服务器手动构建JSON请求时,服务器运行良好。当我从这里使用JSON库时:http://jsonrpcphp.org/我只得到一个错误响应"Array"作为回报。

我不确定我做错了什么,因为我已经测试了服务器,当我不使用PHP库时,它可以工作。

我检查了一下,内容类型设置为"application/json"。

以下是PHP代码:

$server= new jsonRPCClient("http://$serveraddress:$port");

try {
    echo($server->do_stop());
} catch (Exception $e) {
    echo "caught exception: ", $e->getMessage() ,"<br />";
}

编辑:

下面是$server对象的print_r(localhost之前应该有http://,但我不能把它放进去):

jsonRPCClient Object ( [debug:jsonRPCClient:private] => [url:jsonRPCClient:private] => localhost:3000[id:jsonRPCClient:private] => 1 [notification:jsonRPCClient:private] => [proxy] => ) 

do_stop()只是引发一个异常"请求错误:数组"

第2版:解决了问题,结果发现我请求的方法不正确。我忘了我把名字改成了stop()。

逻辑错误。。。

构造ur对象,将调试标志设置为true

 $server= new jsonRPCClient("http://$serveraddress:$port", true);

读取json-rpc客户端的源代码,错误似乎来自ur服务器:

    // final checks and return
    if (!$this->notification) {
        // check
        if ($response['id'] != $currentId) {
            throw new Exception('Incorrect response id (request id: '.$currentId.', response id: '.$response['id'].')');
        }
        if (!is_null($response['error'])) {
            throw new Exception('Request error: '.$response['error']);
        }
        return $response['result'];
    } else {
        return true;
    }