2017-08-12 11 views
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-Typetext/plain;charset=UTF-8はまだあります。私は間違って何をしていますか?

+0

[フェッチ:ポストjsonデータ、アプリケーション/ jsonのテキスト/プレーンへの変更]の可能な複製(https://stackoverflow.com/questions/39689386/fetch-post-json-data-application-json-change-to) -text-plain) – CodeZombie

答えて

1

no-corsリクエストでは、Content-Typeリクエストヘッダーを無効にすることはできません。

モードをcorsに変更します。

+0

あなたは正しいですか? – guest271314

関連する問題