is response.redirect always an http GET response?

11,274

Solution 1

In most API's the standard redirect implementation does a 302 which is indeed per definition GET. As per your question history you're familiar with ASP.NET, I'll however add examples for Java Servlets as well.

ASP.NET:

Response.Redirect("http://google.com");

Servlet:

response.sendRedirect("http://google.com");

It implicitly sets the response status to 302 and the Location header to the given URL.

When the current request is a POST request and you want to redirect with POST, then you need a 307 redirect. This is not provided by the standard API, but it's usually just a matter of setting the appropriate response status and header.

ASP.NET:

Response.Status = "307 Temporary Redirect";
Response.AddHeader("Location", "http://google.com");

Servlet:

response.setStatus(307);
response.setHeader("Location", "http://google.com");

Note that this will issue a security/confirmation warning on the average client which requests the enduser for confirmation to send the POST data to another location.

Solution 2

Assuming that you are using asp.net, maybe server.transfer might be what you are searching for. Instead of sending the new url back to the client, you can pass the processing to another page and keep the form state.

Solution 3

Response.redirect uses only GET..It can't be a post..And in between what is the language?

Solution 4

A redirect is an Http response sent to the client. The response contains an Http Header called Location which must contain an absolute url.

The client then issues a GET request against this url.

So, no, POST is not an option.

More details here: http://en.wikipedia.org/wiki/URL_redirection

Share:
11,274
Rodniko
Author by

Rodniko

Updated on June 04, 2022

Comments

  • Rodniko
    Rodniko almost 2 years

    is response.redirect always an http GET response? or it could be POST?....

  • Piotr Dobrogost
    Piotr Dobrogost over 12 years
    The client then issues a GET request against this url. It does not have to be GET request. For instance after 307 redirect it should be the original http method.
  • kommradHomer
    kommradHomer almost 12 years
  • Sudheer Kumar
    Sudheer Kumar about 10 years
    how can I send Request parameters using response.setHeader("Location","other server site.com")