0

I have a webserver that return response as,

HTTP/1.1 302 Found
message://ActualMessage

This works well for UI Clients such as Android and iOS, but how can I handle this case on a web browser?

For example, a browser request to

GET https://myserver.com HTTP/1.1

And a response looks like,

HTTP/1.1 302 Moved Temporary

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="message://ActualMessage">here</a>.</h2>
</body></html>

Unfortunately can't change the server to not return that response. I am not seeing a way to how to get this response from the browser. A native WebView can easily handle that response.

Darshan
  • 35
  • 1
  • 4
Imran Qadir Baksh - Baloch
  • 32,612
  • 68
  • 179
  • 322
  • 4
    What library are you using in your js? Xmlhttprequest? jQuery Ajax? Fetch? Axios? Some other? – Ferrybig May 16 '19 at 06:31
  • 1
    How do you make this request through js? – Lu Chinke May 16 '19 at 06:32
  • Unfortunately its normal http request not an ajax request – Imran Qadir Baksh - Baloch May 16 '19 at 06:43
  • 1
    It seems rather unclear what you want to achieve. What does it mean "how can I handle this case with web"? – JeffRSon Jun 28 '19 at 19:12
  • @user960567 You still haven't told us how you were making the request. Did your browser just navigate to an URL where the server sent this response? – Bergi Jun 29 '19 at 13:48
  • What web server are you using? – Toby Mellor Jun 29 '19 at 13:51
  • @Bergi yes browser send POST request when click the submit button on page – Imran Qadir Baksh - Baloch Jun 30 '19 at 06:09
  • @TobyMellor I am using ASP.NET/IIS – Imran Qadir Baksh - Baloch Jun 30 '19 at 06:09
  • 3
    @user960567 You *really* should fix the server to send a proper response, probably with a `Location` header to redirect to. But if that's not possible, change the form to intercept the `submit` event and send an ajax request instead, where you can access the response headers with js and deal with them however you want. – Bergi Jun 30 '19 at 10:38
  • The server MUST provide the Location header according to [RFC 1945, section 9.3](https://tools.ietf.org/html/rfc1945#section-9.3). This is a malformed response if a 302 response doesn't contain the Location header. Are you really asking for a technique to make your client deal with this malformed response? You should be fixing the problem at the server, because all other clients (except the one you're about to create) will still choke on the malformed response. – Wyck Jul 04 '19 at 13:19
  • I'd like to challenge one of your claims: Does a "native WebView" **really** handle this? It seems sketchy to sift through the body of the 302 response looking for `href` attributes of `a` tags and then following the links. – Wyck Jul 04 '19 at 13:23
  • @Wyck maybe the server was written like that on purpose? So while it looks like webserver it's protected from normal web traffic (stupid but possible). – mx0 Jul 05 '19 at 17:30

1 Answers1

0

Browser will follow "302 Redirect". There is no way how to intercept it.

However, as a workaround you may try:

  • use xmlHTTPRequest may work (if server allows, see this answer for possible issues)
  • iframe may work
Andrii Muzalevskyi
  • 3,261
  • 16
  • 20