簡體   English   中英

錯誤的Content-Type替代了獲取HTTP請求

[英]Wrong Content-Type being substituted for fetch http request

我在客戶端上有以下代碼:

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,這是我的要求:

在此處輸入圖片說明

編輯:當我刪除JSON.strigify() ,也會省略Content-Type和Request負載。 這是一個例子:

沒有JSON.stringify()的結果

您已將mode: 'no-cors',設置為mode: 'no-cors',因此無法將'Content-Type''application/json' 它不是Content-Type安全值之一

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM