[英]POST getting 415 (Unsupported Media Type) while POSTMAN returns 200
似乎是一个简单的问题,但其他任何地方都建议在我尝试过的“标题”中添加“application/json”。
'Accept' 和 'Content-Type' 都是“application/json”。 还尝试了 json 和 stringfy 'Body',但在 Chrome 扩展 JavaScript 上继续获得 415。
textArraySample = ["sample","sample2"];
var serverUrl = "https://webappcontentnotification.azurewebsites.net/api/ContentUpload";
const body={
"textbatch":textArraySample,
"userId": userId,
"url": window.location.href
}
let result =
fetch(serverUrl, {
method: 'POST',
mode: "no-cors",
headers: {
'Accept': "application/json",
'Content-Type': "application/json"
},
body: JSON.stringify(body)
})
.then(response => {
console.log('response:', response);
})
.catch((error) => {
console.log('Error:', error);
});
没有看到其他地方提到过这个。 根本原因是在使用“Mode: no-cors”时无法将“Content-Type”设置为“application/json”。 链接在这里
mode: "no-cors" 只允许请求中的一组有限的标头:
接受
接受语言
内容语言
Content-Type 值为 application/x-www-form-urlencoded、multipart/form-data 或 text/plain
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.