简体   繁体   中英

Access-Control-Allow-Origin not working correctly

I'm making a cross domain POST request. I added Access-Control-* headers to the web server, but Google Chrome javascript console raises:

XMLHttpRequest cannot load http://api.sharee.dev:3000/assets.json. Origin http://sharee.dev:4000 is not allowed by Access-Control-Allow-Origin.
POST http://api.sharee.dev:3000/assets.json undefined (undefined)

Here are all the packets that are transferred during the request: http://pastie.org/1882455

As you can see it stills sends the POST request after OPTIONS request. It doesn't work in Firefox either. Firefox shows that POST request was sent to the server and the response code was 200, but the response itself is empty.

The Access-Control-Allow-Origin and Access-Control-Allow-Credentials headers should be a part of any CORS response (including the preflight OPTIONS request and the POST request). Your current example shows them only on the OPTIONS response.

you can check the answer for the following post in superuser. I had happened to post the problem on chromium-dev google groups a while back.

https://superuser.com/questions/384871/how-to-override-access-control-allow-origin-restriction-in-google-chrome

Grappling with exactly the same myself but with my server access, finally proxied all such calls to get it running. But this will not be ideal in distribution. Have you tried matching up headers and/or values requested vs. those responded? Also, in my research, browser version can play. Please give the exact versions you are debugging now.

我认为您还需要在POST响应上放置Access-Control标头?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM