gpt4 book ai didi

json - 无法解码 HTTP 请求中的 JSON

转载 作者:可可西里 更新时间:2023-11-01 16:49:58 25 4
gpt4 key购买 nike

我正在使用 Parse Cloud CodeDelete Multiple Messages from Iron.io 发出“DELETE”HTTP 请求.

它使用与对 Get Message from the Queue 的“GET”请求完全相同的 header 和 url :

    headers: {        'Content-Type': 'application/json;charset=utf-8',            'Authorization': 'OAuth ' + ironToken      },

The 'GET' request does work, whether I put method: 'GET' or not inside Parse.Cloud.httpRequest().It does work even if I send some data as body: (which are ignored).

However, for a 'DELETE' request, I need to send body:

 body: {
'ids': ['someMessageId']
}

此请求失败并显示非常无用的消息:

{"status":400,"headers": {"Access-Control-Allow-Origin":"*", "Connection":"keep-alive", "Content-Length":"32", "Content-Type":"application/json", "Date":"Tue, 06 May 2014 10:15:27 GMT"},"text":"{\"msg\":\"Failed to decode JSON.\"}","data":{"msg":"Failed to decode JSON."},"buffer":[ ...],"cookies":{}}

知道为什么会发生这种情况吗?我还能测试什么?

最佳答案

 body: {
'ids': ['someMessageId']
}

不是有效的 json 对象。你到处都需要双引号:

 "body": {
"ids": ["someMessageId"]
}

关于json - 无法解码 HTTP 请求中的 JSON,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23492054/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com