클라이언트 브라우저에서 fetch api를 사용하면 GET 또는 POST에 문제가 없지만 가져 오기 및 삭제에 문제가 있습니다. DELETE 요청 메소드를 OPTIONS로 변경하는 것 같습니다.DELETE로 api 문제 가져 오기 - cors가 좋은 경우에도 OPTIONS가 변경됩니다.
연구의 대부분은 코르 문제가되는 것으로 나와 있지만, 나와 관련된 문제는 다룹니다.
이것은 valid fetch spec api link 경우 잘 모르겠습니다 만 보여줍니다 :
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);
});
},
크롬 네트워크 탭 :
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