鍍金池/ 問答/HTML/ 這是個誤會--cors跨域put請求,options報404

這是個誤會--cors跨域put請求,options報404

我都不好意思說,我把地址寫錯了,大家請忽略下面的內(nèi)容

=====================================================

跨域發(fā)PUT請求,會發(fā)options預(yù)檢請求,這個道理明白。但是options返回404,請大神幫忙看看~
postman直接發(fā)PUT請求是OK的。

clipboard.png

clipboard.png

主要代碼:

fetch(url, {
    method: 'PUT',
    credentials: 'include',
    headers: new Headers({
      'Content-Type': 'application/json;charset=UTF-8'
    }),
    body: JSON.stringify({ username: "xxx" })
  }).then(function (response) {
    console.log(response);
    return response.json();
  }).then(function (json) {
    return json;
  });
回答
編輯回答
熊出沒

如果你確認(rèn)你的請求的地址是正確的話,并且請求存在跨域,
請在響應(yīng)頭Access-Control-Allow-Methods里也加上OPTION請求,
目前你的響應(yīng)頭里沒有配置option請求,
clipboard.png

2018年9月21日 21:18