我正在尝试使用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方法不允许