is response.redirect always an http GET response?

2019-03-01 05:22发布

问题:

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

回答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.



回答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.



回答3:

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



回答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



回答5:

Contrary to most answers here the redirected HTTP request is only GET if

  • the original request was GET, or
  • the status code was 303, or
  • the status code was 301 or 302 and the original request was POST.