HTTP response with redirection but no redirect?

I want the browser to reflect some other URL than the one used to create the request, but without going back to the server.

I could do this:

POST /form HTTP/1.1 ... 

... and then return:

 HTTP/1.1 200 OK Location: /hello 

But this will cause a redirect, the browser will again request a url / hello.

I would just like to tell the browser that although the request you just sent was POST / some_url, the actall resource that I am returning now is actually called GET / hello / 1, but without any conversion. That is the location: ...

Is there a way to do this using JavaScript or the base = "" attribute? Will this tell the browser to ask / hello / 1 when instead I pressed F5 (update) after sending a warning?

+4
redirect
source share
2 answers
 HTTP/1.1 200 OK Location: /hello 

Actually, this probably won't work; it should be a 30x status, not 200 ("303 See" Other "is best suited for a POST response), and" Location should be a complete, absolute URL. "

(If your script just says β€œLocation: / relativeurl without 30x status, CGI servers usually do an internal redirect by picking a new URL and returning it without telling the browser anything funny. It may sound like you want, but in reality in fact, this is not so, because from the point of view of the browser, it is no different from the original script returning 200 and the direct page.)

But this will cause a redirect, the browser will again request a url / hello.

In practice, this is probably not as bad as you think thanks to HTTP / 1.1 keep-alives. The client should be able to immediately respond to the redirection (in the next packet) if it is on the same server.

Is there a way [...] This will tell the browser to request / hello / 1 when I hit F5 (update) instead, after sending a warning?

Nope. Stick to the POST-Redirect-GET model to solve this problem.

+5
source

Not. Http is stateless, and each request has one answer. When you send a message, you need to immediately redirect to the receive page to prevent double entry - you do not want it to sit at this URL. A redirect is what tells the browser that it is on a new page. This is how it works.

0
source

All Articles