is response.redirect always an http GET response?

2019-03-01 05:16发布

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

5条回答
神经病院院长
2楼-- · 2019-03-01 05:54

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

查看更多
3楼-- · 2019-03-01 05:55

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.

查看更多
做自己的国王
4楼-- · 2019-03-01 06:00

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.

查看更多
看我几分像从前
5楼-- · 2019-03-01 06:02

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

查看更多
唯我独甜
6楼-- · 2019-03-01 06:02

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.
查看更多
登录 后发表回答