fetch()不是POST JSON主体

时间:2017-04-11 20:53:36

标签: json reactjs fetch-api

fetch()API不是POST这个JSON主体。

var j = {
    "addressee": "James"
};
return fetch('http://requestb.in/blahblahblah', {
    method: 'POST',
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
        'Cache-Control': 'no-cache'
    },
    body: JSON.stringify(j)
})

RequestBin中绝对没有请求正文出现。什么可能发生在身体?调试JSON.stringify(j)表明它确实正确地格式化了正文。

1 个答案:

答案 0 :(得分:0)

原来fetch()API正在发送OPTIONS预检请求,以查看服务器上的CORS配置。删除fetch()请求中的标头可以防止这种情况发生。