获得;“错误”=&燃气轮机&引用;数组";来自python JSON服务器和PHP客户端的数组响应
我用python编写了一个简单的JSON RPC服务器,作为python程序的接口。当我使用curl从服务器手动构造JSON请求时,服务器工作正常。当我从这里使用JSON库时:我只得到一个错误响应“Array” 我不确定我做错了什么,因为我已经测试了服务器,当我不使用PHP库时,它可以工作 我已经检查过了,内容类型设置为“application/json” 下面是PHP代码:获得;“错误”=&燃气轮机&引用;数组";来自python JSON服务器和PHP客户端的数组响应,php,python,json,client,rpc,Php,Python,Json,Client,Rpc,我用python编写了一个简单的JSON RPC服务器,作为python程序的接口。当我使用curl从服务器手动构造JSON请求时,服务器工作正常。当我从这里使用JSON库时:我只得到一个错误响应“Array” 我不确定我做错了什么,因为我已经测试了服务器,当我不使用PHP库时,它可以工作 我已经检查过了,内容类型设置为“application/json” 下面是PHP代码: $server= new jsonRPCClient("http://$serveraddress:$port");
$server= new jsonRPCClient("http://$serveraddress:$port");
try {
echo($server->do_stop());
} catch (Exception $e) {
echo "caught exception: ", $e->getMessage() ,"<br />";
}
dou_stop()只会引发一个异常
“请求错误:数组”
编辑2:
解决了RPO问题,结果证明我请求的方法不正确。我忘了我把名字改为stop()
逻辑错误…构造您的对象,将调试标志设置为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;
}
当我查看代码时,我发现了相同的东西。可能是rewest错误导致服务器返回错误吗?我已经测试了服务器,它在不使用PHP的情况下运行良好。是否在python服务器中检查请求?检查curl和json-rpc请求之间的区别。您可以从问题中的服务器粘贴一些服务器代码/调试信息。
// 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;
}