【发布时间】:2018-01-21 03:40:09
【问题描述】:
我正在向服务器发出远程获取请求。有效载荷是 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。我做错了什么?
【问题讨论】:
标签: javascript json reactjs fetch-api