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 header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response

See original GitHub issue

I send POST request to other server api and get error

XMLHttpRequest cannot load http://example.com/api/v1/auth. Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response.

After that, I config vue headers like this.

Vue.http.options.xhr = {withCredentials: true}
Vue.http.options.emulateJSON = true
Vue.http.options.emulateHTTP = true
Vue.http.options.crossOrigin = true

Vue.http.headers.common['Access-Control-Allow-Origin'] = '*'
Vue.http.headers.common['Content-Type'] = 'application/x-www-form-urlencoded'
Vue.http.headers.common['Accept'] = 'application/json, text/plain, */*'
Vue.http.headers.common['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, Authorization, Access-Control-Allow-Origin'

but, that error has occurred. Can you give me correct config Vue-resouce to fix this problem.

Thanks so much.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:11 (2 by maintainers)

github_iconTop GitHub Comments

20reactions
adexphemcommented, Aug 11, 2017

I tried this inside js/bootsrap.js

window.axios.defaults.headers.common = { ‘Accept’: ‘application/json’, ‘Content-Type’: ‘application/json’ };

That worked for me after spending more than 4 hours battling with same error. I’m on Laravel, Vuejs 2.4.2 and using Axios

6reactions
lephuhaicommented, Feb 4, 2017

@steffans Sorry, I’m using postman for send request to api. It still work. I don’t think problem lies in server?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Request header field Access-Control-Allow-Headers is not ...
When you start playing around with custom request headers you will get a CORS preflight. This is a request that uses the HTTP...
Read more >
Access-Control-Allow-Headers - HTTP - MDN Web Docs
The Access-Control-Allow-Headers response header is used in response to a preflight request which includes the ...
Read more >
Request header field content-type is not allowed by Access ...
My netlify function has these headers set up: const headers = { 'Access-Control-Allow-Origin': '*', 'Access-Control-Allow-Headers': ...
Read more >
CORS error: Request header field Authorization is not allowed ...
The CORS error "Request header field Access-Control-Allow-Headers is not allowed by Access-Control-Allow-Headers in preflight response" occurs when your browser ...
Read more >
'Request header field authorization is not allowed by Access ...
'Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response.' in a POST Request #2345.
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