CORS request isn't allowed despite headers being set

后端 未结 1 1911
误落风尘
误落风尘 2021-01-06 23:55

I get the following error trying to do an XHR request. I\'ve setup CORS response headers, but apparently something is wrong. Can anyone spot the error?

<
相关标签:
1条回答
  • 2021-01-07 00:38

    It seems that proper handling of the pre-flight OPTIONS request is necessary, but NOT SUFFICIENT for cross-site resource requests to work.

    After the OPTIONS request comes back with satisfactory headers, all responses to any subsequent requests to the same URL also have to have the necessary "Access-Control-Allow-Origin" header, otherwise the browser will swallow them, and they won't even show up in the debugger window.

    So it will look like the browser cancelled the request because of some problem in the OPTIONS response, but actually, the browser is looking at the response headers from the real request and then rejecting them.

    (Answer copied from my own similar question Access-Control-Allow-Origin header not working - What am I doing wrong? in case it's the same thing)

    0 讨论(0)
提交回复
热议问题