0
サーバへのリモートフェッチ要求を行っています。ペイロードは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)
しかし、クロム開発ツールのコンソールで、リクエストのヘッダContent-Type
はtext/plain;charset=UTF-8
はまだあります。私は間違って何をしていますか?
[フェッチ:ポストjsonデータ、アプリケーション/ jsonのテキスト/プレーンへの変更]の可能な複製(https://stackoverflow.com/questions/39689386/fetch-post-json-data-application-json-change-to) -text-plain) – CodeZombie