2014-10-05 55 views
-1

我已經在python中編寫了一個簡單的JSON RPC服務器作爲python程序的接口。當我使用curl從它手動構建JSON請求時,服務器工作正常。當我從這裏使用JSON庫時:http://jsonrpcphp.org/我剛收到一個錯誤響應「Array」。從python JSON服務器和PHP客戶端獲取「error」=>「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 />"; 
} 

編輯:

這裏的$服務器對象的print_r的(本地主機應具備的http://之前,但我不能把它):

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

do_stop()只是引發一個異常 「請求錯誤:數組」

編輯2: 解決了這個問題,結果證明我正在請求一個不正確的方法。我忘了將名稱更改爲stop()。

邏輯錯誤......

+0

'print_r'你的數據 – 2014-10-05 07:14:52

回答

1

構建烏爾對象調試標誌設置爲true

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

讀取JSON RPC客戶端的source code,好像錯誤是從烏爾服務器來:

// 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; 
    } 
+0

當我看到了代碼後,我發現了同樣的東西。難道這是因爲某個錯誤導致服務器返回錯誤? 我已經測試了服務器,並且在不使用PHP時它工作正常。 – user269187 2014-10-05 08:26:16

+0

檢查python服務器中的請求嗎?檢查curl和json-rpc之間請求的區別。您可以在問題中從服務器粘貼一些服務器代碼/調試信息。 – Todor 2014-10-05 08:48:46

相關問題