Vous êtes sur la page 1sur 3

7/4/2017 HTTPRedirection|HttpWatch

(/)

HTTP Gallery

Jump to ...

7. Redirection
HTTP allows servers to redirect a client request to a dierent location. Although, this will usually result in another network round trip, it has
some useful applications:

A web application may use redirection to navigate between parts of the application.

If content has moved to a dierent URL or domain name, redirection can be used to avoid breaking old URLs or bookmarks.

It is possible to convert a POST request to a GET request using redirection.

A client can be directed to use its local cache for content that has not changed.

A server species redirection by returning a 3xx status code:

301 This indicates that the content now resides permanently at the location specied by the Location header and future requests should be
directed to this location.

302 Same as 301, except that the new location is temporary and future requests should still be sent to the original location. Another feature
of this status code is that if the original request was a POST the client will change to using a GET when it re-issues the request (See
below for more details).

303 This status code was intended to be the only status code that caused a POST to be converted to a GET. However, most browsers treat a
302 like a 303.

304 Used in response to an If-Modied header to redirect a request to the browser's local cache.

305 A 305 response is used to specify that a request must be resubmitted through the HTTP proxy in the Location header

Redirecting POST requests


In certain situations, interactive web applications must use POST requests (see 6. Methods (../methods/)). However, this causes a problem with
the resulting web page. If the user attempts to refresh the page they are presented with a message box asking them whether they want to retry
the previous action. Another problem is that page may have been marked as not cacheable for security reasons. If the user clicks the Back
button and encounters a non-cacheable page resulting from a POST the following is displayed in IE (if you have disabled Friendly HTTP
Messages):

https://www.httpwatch.com/httpgallery/redirection/ 1/3
7/4/2017 HTTPRedirection|HttpWatch

These problems can be avoided by redirecting the result of a POST to a GET using a 302 status code. (See the example below)

Example 7
Redirecting a POST

This is one of the samples from Example 6 that has been modied to redirect the result of the POST request. If you refresh this page after
modifying the account balance, there is no retry message box displayed and the account balance will not change:

Account Balance = $1000

Amount to debit: $ 10 SUBMIT

REFRESH THIS PAGE

Using HttpWatch with Example 7

To view the HTTP headers discussed on this page:

1. Open HttpWatch by right clicking on the web page and selecting HttpWatch from the context menu

2. Click on Record to start logging requests in HttpWatch

3. Click on the Submit button above

4. You'll see a POST 302 entry that redirects to a GET on this page.

<6. HTTP METHODS (../METHODS/) 8. COMPRESSION> (../COMPRESSION/)

Ready to get started?

TRY FOR FREE

(/DOWNLOAD/)
BUY NOW (/BUY/)

https://www.httpwatch.com/httpgallery/redirection/ 2/3
7/4/2017 HTTPRedirection|HttpWatch

HttpWatch
Features (/features/httpdebugger.aspx)
Compare Editions (/editions.aspx)
New in Version 10.x (/newin10x.aspx)
Download (/download/)
Pricing (/buy/)

Our Customers
Who is using it? (/#customers)
What are they saying? (/#quotes)

Learning & Documentation


HttpWatch Blog (http://blog.httpwatch.com)
HTTP Gallery (/httpgallery/)
HttpWatch Help (http://help.httpwatch.com)
HttpWatch Automation Reference (http://apihelp.httpwatch.com)

Support
Technical Support (/support/)
About Us (/company/)
Contact Us (/company/)
Blog (http://blog.httpwatch.com)
Twitter (https://twitter.com/httpwatch)

Search (/search/) Terms & Conditions (/company/terms.aspx) Privacy Policy (/company/privacy_policy.aspx) Copyright (/company/copyright.aspx)

Copyright 2017 Neumetrix Limited (/)

https://www.httpwatch.com/httpgallery/redirection/ 3/3

Vous aimerez peut-être aussi