gpt4 book ai didi

javascript - 错误的 Content-Type 被替换为 fetch http 请求

转载 作者:行者123 更新时间:2023-11-28 15:08:00 24 4
gpt4 key购买 nike

我在客户端上有此代码:

return fetch('http://localhost:8080/api/authenticate', {
method: 'POST',
mode: 'no-cors',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
username: 'admin',
password: 'admin',
}),
});

当我出于某种原因发送此请求时,Content-Type 被替换为 text/plain;charset=UTF-8。这使得我的服务器端请求失败,因为它只接受 application/json 请求。我在这里做错了什么?我使用的是 Chrome 51,这是我的请求:

enter image description here

编辑:当我删除 JSON.strigify() 内容类型和请求有效负载时,也会被省略。这是一个例子:

Result without JSON.stringify()

最佳答案

您已设置mode: 'no-cors',,因此您无法将'Content-Type'设置为'application/json' 。它不是 safe values for Content-Type 之一.

关于javascript - 错误的 Content-Type 被替换为 fetch http 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38060602/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com