question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Request not responding, Why an OPTIONS method is sent before my request ?

See original GitHub issue

I’ve been having a problem i don’t really have using jQuery Ajax methods, when i use axios, my request sends one Request Method:OPTIONS in it’s header and doesn’t respond (neither GET nor POST request).

With jQuery the same endpoint works fine, but with axios it keeps telling me :

Request header field Content-Type is not allowed by Access-Control-Allow-Headers in preflight response.

though i didn’t sent any Access-Control-Allow-Headers with my request. I even tried :

axios.defaults.headers.common['Access-Control-Request-Headers'] = null
axios.defaults.headers.common['Access-Control-Request-Method'] = null

any ideas ? bug ? normal ?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:17
  • Comments:21 (1 by maintainers)

github_iconTop GitHub Comments

123reactions
nickuraltsevcommented, Oct 15, 2016

axios uses the application/json format by default, while jQuery uses application/x-www-form-urlencoded. Cross site requests in the former format are always preflighted, while cross site requests in the latter format may be not preflighted. Please see this for details.

Hope this helps!

99reactions
SamVerschuerencommented, Oct 12, 2016

Have a look at CORS and more specifically to the pre-flighted requests.

Basically the OPTIONS request is used to check if you are allowed to perform the GET request from that domain and what headers can be used for that request. This is not axios specific.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is an OPTIONS request sent and can I disable it?
According to the CORS strategy (highly recommend you read about it) You can't just force the browser to stop sending OPTIONS request if...
Read more >
Why is my browser sending an OPTIONS HTTP request ...
A preflight request, is a mechanism in CORS by the browser to check if the resource destination is willing to accept the real...
Read more >
OPTIONS - HTTP - MDN Web Docs
In CORS, a preflight request is sent with the OPTIONS method so that the server can respond if it is acceptable to send...
Read more >
Why Is an OPTIONS Request Sent? - Baeldung
The OPTIONS request mentioned in the introduction is a preflight request, which is part of the CORS (Cross-Origin Resource Sharing).
Read more >
RFC 7231: Hypertext Transfer Protocol (HTTP/1.1)
In order to improve the server's guess, a user agent MAY send request ... the origin server SHOULD respond with the 405 (Method...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found