繁体   English   中英

在获取请求中设置Content-Type不起作用

[英]Setting Content-Type in fetch request not working

我正在对服务器执行远程获取请求。 有效负载为JSON格式,因此我想将Content-Type标头更改为application/json 我已使用以下代码执行此操作:

let email = document.getElementById("email").value
let password = document.getElementById("password").value

const body = {"email":email, "password":password}
const headers = new Headers({
    "Content-Type": "application/json",
    "Content-Length": JSON.stringify(body).length
})
const options = {
    method: "POST",
    mode: "no-cors",
    headers: headers,
    body: JSON.stringify(body)
}
console.log(options)
const response = await fetch('http://xx.xx.xx.xxx/login', options)
const json = await response.json()
console.log(json)

但是,在Chrome开发人员工具控制台中,请求的Content-Type标头仍为text/plain;charset=UTF-8 我究竟做错了什么?

no-cors请求不允许覆盖Content-Type请求标头。

将模式更改为cors

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM