When I send a delete request to a certain endpoint, for example with httpie from terminal like
http delete http://localhost:8181/admin/applications/uspecs
I get a valid behavior, as in { success: true }
as response body.
But when I do
fetch (
'http://localhost:8181/admin/applications/uspecs',
{ method: 'DELETE' }
)
.then(res => doSomethingWithResponse())
.catch(err => console.error(err))
In javascript code, then I get a
Fetch API cannot load http://localhost:8181/admin/applications/uspecs.
Method DELETE is not allowed by Access-Control-Allow-Methods in preflight response.
error on the console. What am I missing? I am getting a valid methods list on options request.
When I send a delete request to a certain endpoint, for example with httpie from terminal like
http delete http://localhost:8181/admin/applications/uspecs
I get a valid behavior, as in { success: true }
as response body.
But when I do
fetch (
'http://localhost:8181/admin/applications/uspecs',
{ method: 'DELETE' }
)
.then(res => doSomethingWithResponse())
.catch(err => console.error(err))
In javascript code, then I get a
Fetch API cannot load http://localhost:8181/admin/applications/uspecs.
Method DELETE is not allowed by Access-Control-Allow-Methods in preflight response.
error on the console. What am I missing? I am getting a valid methods list on options request.
Share Improve this question edited Aug 22, 2019 at 1:44 nabn asked Feb 22, 2016 at 8:36 nabnnabn 2,4081 gold badge25 silver badges27 bronze badges 8- Read about cross-origin resource sharing (CORS) - stackoverflow./questions/25845203/understanding-cors. – Ondrej Svejdar Commented Feb 22, 2016 at 8:39
-
In the OPTIONS response, I am getting
allow: DELETE, HEAD, GET, OPTIONS, POST
list. That should do it, no? @OndrejSvejdar – nabn Commented Feb 22, 2016 at 8:45 - Can you use fiddler poser to send OPTIONS request to the endpoint and post the response you're getting. Also the post is confusing - make sure the OPTIONS and DELETE request are send to the same endpoint (in your post those are different). – Ondrej Svejdar Commented Feb 22, 2016 at 8:51
- updated. @OndrejSvejdar – nabn Commented Feb 22, 2016 at 9:06
- 2 I don't see any OPTIONS response in your post. please post the full response headers to that request. – ThiefMaster Commented Feb 22, 2016 at 9:09
1 Answer
Reset to default 5You need to send the Access-Control-Allow-Methods
header containing the allowed methods. Currently your header is named methods
.