Chrome cancels CORS XHR upon HTTP 302 redirect

前端 未结 4 1018
梦毁少年i
梦毁少年i 2020-11-27 04:42

It looks like according to the CORS Spec, GET and POST requests should transparently follow 302 redirects. But Chrome is canceling my request.

Here\'s the JS that d

4条回答
  •  一生所求
    2020-11-27 04:54

    I found this post about setting the correct Access-Control-Allow-Origin CORS header on your 302 response to be helpful, at least in my similar-sounding case.

    Investigation of the problem showed that his XHR was not landing on the CORS-enabled URL directly, but was being redirected to it through an HTTP 302 (redirect) response.

    So bear in mind that the redirecting URL must also include an Access-Control-Allow-Origin header, else the browser will stop right there with its attempted cross-domain request.

    I've also found that setting additional CORS headers above and beyond Access-Control-Allow-Origin will often result in a cancelled transaction.

提交回复
热议问题