获取 api "Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)"响应



Getting("exception":"400错误请求:无法解码JSON对象:期望值:第1行第1列(char 0("消息":"无效输入"(作为回应。

var params = JSON.stringify(dummy_obj);
var userKey = 'apikey-123';
fetch(`someurl?key=${userKey}&`, {
method: 'POST',
headers: {
'Access-Control-Allow-Origin': '*',
Accept: 'text/plain',
'Content-Type': 'application/json',
},
body: {params},
})
.then(response => response.text())
.then(response => {
console.log(response);
})
.catch(error => {
console.error(error);
});
}

400 Bad Request表示您发送到端点的请求的正文在某种程度上是无效的。它读起来就像服务器告诉你,它在试图解析你给它的JSON时抛出了一个异常。我会检查你的params并确保它是有效的。

最新更新