【问题标题】:Error 32600: JSON-RPC Request must be an object错误 32600:JSON-RPC 请求必须是对象
【发布时间】:2015-09-11 18:27:30
【问题描述】:

我的要求是:

var req = {"action": "UserAPI","method": "Authenticate","data": ["un","pw"],"type": "rpc", "tid": "1"}
$.post("http://localhost/myServer/RPC/ROUTER",req, function(result){
        console.log(result.responseText);
    });

回复是:

"{ "jsonrpc" : "2.0", "error" : { "code" : -32600, "message" : "JSON-RPC Request must be an object." }, "tid" : null }"

Request 已经是一个对象。这有什么问题?

【问题讨论】:

    标签: jquery json ajax rpc json-rpc


    【解决方案1】:

    如果服务器期待 JSON-RPC 请求,那么您需要按照它想要的方式格式化您的请求。

    JSON-RPC 意味着服务器想要一个 JSON 字符串作为 POST 正文,而不是像您发送的那样形成数据。

    试试这个:

    var req = {
        "action": "UserAPI",
        "method": "Authenticate",
        "data": ["un","pw"],
        "type": "rpc", 
        "tid": "1"
    };
    
    $.ajax({
        url: "http://localhost/myServer/RPC/ROUTER",
        type: 'post',
        // This tells the server we are sending
        // JSON data as the payload
        contentType: 'application/json',
        // Encode the object as a JSON string
        data: JSON.stringify(req),
        // The response is JSON
        dataType: 'json',
        success: function(result){
            // This should be parsed for you, so `result` will be an object
            console.log(result);
        }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-04-23
      • 2017-08-31
      • 2018-08-17
      • 2017-11-20
      • 2021-07-01
      相关资源
      最近更新 更多