response.redirect 总是 http GET 响应吗? [英] is response.redirect always an http GET response?

查看:24
本文介绍了response.redirect 总是 http GET 响应吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

response.redirect 总是 http GET 响应吗?或者它可能是POST?....

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

推荐答案

在大多数 API 中,标准重定向实现执行 302,这确实是每个定义的 GET.根据您的问题历史记录,您对 ASP.NET 很熟悉,但我也会为 Java Servlet 添加示例.

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");

服务端:

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

它将响应状态隐式设置为 302,并将 Location 标头设置为给定的 URL.

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

current 请求是 POST 请求并且您想使用 POST 重定向时,那么您需要一个 307 重定向.这不是由标准 API 提供的,但通常只是设置适当的响应状态和标头的问题.

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");

服务端:

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

请注意,这将在普通客户端上发出安全/确认警告,请求最终用户确认将 POST 数据发送到另一个位置.

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.

这篇关于response.redirect 总是 http GET 响应吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆