Juzer Ali
Juzer Ali

Reputation: 4167

302 redirect to a different domain fails silently

I have this peculiar flow.

  1. I make an XMLHttpRequest to my server
  2. My server sends a 302 redirect to a different domain. The server at that domain is CORS compliant.
  3. The browser possibly follows the Location. I don't know what exactly happens here because this request doesn't surface in Chrome's debugging tools.
  4. Finally I am left with an awkward looking request/response in chrome debugger.

Has someone been able to achieve response from cross domain redirection via XMLHttpRequest, or is it even possible?

Upvotes: 3

Views: 2315

Answers (2)

iCollect.it Ltd
iCollect.it Ltd

Reputation: 93551

It is possible, but can only be solved on the server.

Rather than redirect (return a 302 to the client), you need to make the request from your server to the other website and return its response to the client. Basically pass the incoming stream from the other server back as your data stream.

This avoid any cross-domain security problems.

Upvotes: 0

Juzer Ali
Juzer Ali

Reputation: 4167

Browsers transparently follows 302 redirects and it doesn't even show up in chrome debugging tools. At the moment there is no way around it. I debugged the http call from curl.

Upvotes: 2

Related Questions