简体   繁体   English

错误32600:JSON-RPC请求必须是对象

[英]Error 32600: JSON-RPC Request must be an object

My request is: 我的要求是:

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);
    });

Response is: 回应是:

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

Request is already an object. 请求已经是一个对象。 What is wrong with this? 这有什么问题?

If the server is expecting a JSON-RPC request, then you need to format your request the way it wants. 如果服务器期望JSON-RPC请求,那么您需要按照自己的方式格式化请求。

JSON-RPC means that the server wants a JSON string as the POST body, not form data like you are sending. JSON-RPC意味着服务器需要一个JSON字符串作为POST主体,而不是像您要发送的那样形成数据。

Try this: 尝试这个:

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);
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM