![](/img/trans.png)
[英]Fetch request failing for DELETE method even though CORS headers are present
[英]Fetch api issue with DELETE - changes to OPTIONS even when cors is good
在客戶端瀏覽器中使用fetch api,我沒有遇到GET或POST問題,但我遇到了fetch和DELETE的問題。 它似乎將DELETE請求方法更改為OPTIONS。
大多數研究表明是一個角色問題,但對我來說,我有涵蓋的角色問題。
我不確定這是否是一個有效的fetch spec api鏈接,但它顯示:
CORS安全列出的方法是
GET
,HEAD
或POST
。
我不確定這是否意味着我不能在用cors獲取時使用DELETE,這就是我遇到問題的原因?
瀏覽器代碼:
var request =
new Request(url, {
credentials: 'include',
mode: 'cors',
method: 'DELETE'
});
return fetch(request)
.then(this.fetchError.bind(this))
.then(this.json)
.then((response)=> {
this.set(`uploadState.${index}.value`, false);
})
.catch((e) => {
console.log(e);
});
},
chrome網絡標簽:
Request URL:http://72.12.4.3:9000/api/v1/listings/3/47/image-3-47-1492565415145.jpeg
Request Method:OPTIONS
Status Code:401 Unauthorized
Remote Address:72.12.4.3:9000
Response Headers
view source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:true
Access-Control-Allow-Methods:POST, GET, OPTIONS, DELETE
Access-Control-Allow-Origin:http://72.12.4.3:8000
Connection:keep-alive
Content-Length:25
Content-Type:application/json; charset=utf-8
Date:Wed, 19 Apr 2017 01:36:07 GMT
ETag:W/"19-9NCRiMyz+z1Bt6fGQfcxA"
X-Powered-By:Express
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:
Access-Control-Request-Method:DELETE
Cache-Control:no-cache
Connection:keep-alive
Host:72.12.4.3:9000
If-None-Match:W/"19-9NCRiMyz+z1Bt6fGQfcxA"
Origin:http://72.12.4.3:8000
Pragma:no-cache
Referer:http://72.12.4.3:8000/
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36
OPTIONS
請求是預期的,並且基本上是瀏覽器用於檢查在這種情況下是否允許請求DELETE
的機制。
OPTIONS
請求似乎從您的服務器獲得401 Unauthorized
響應。 這確實會導致請求失敗。 用200 OK
回復。
順便說一句,標題Access-Control-Allow-Headers:
是錯誤的,但這不應該影響任何事情。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.