发布请求在邮递员中有效,但在浏览器中不起作用(405选项错误)

时间:2019-10-15 09:26:53

标签: javascript html post cors fetch

我正在尝试使用JavaScript中的FETCH API调用向API发出发布请求。使用与我在POSTMAN中发送的标题/正文相同的标题/正文。它可以成功运行,但是在Code中实现时会失败。

const headers = { Accept: 'application/json', 'Content-Type': 'application/json', 'x-original-client-component-id': 'blahblah', 'x-client-component-id': 'blahblah', 'Sec-Fetch-Mode': 'cors' };
const options = { method: 'POST', body: JSON.stringify(body), credentials: 'include', headers };

return fetch(url, options)
    .then((payload) => callSomeFunction(payload, documentJson))
    .catch(() => documentJson);

预期结果:是从APi获取JSON对象(就像在POSTMAN中一样)

真实结果:    请求网址:请求的网址    请求方法:OPTIONS    状态码:405方法不允许

0 个答案:

没有答案