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

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

问题描述

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

解决方案

在大多数API中,标准重定向实现确实是每个定义得到。根据您熟悉的ASP.NET问题历史,我将为Java Servlet添加示例。



ASP.NET:

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

Servlet:

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

它隐式设置响应状态为302, Location

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



ASP.NET:

  Response.Status =307临时重定向; 
Response.AddHeader(Location,http://google.com);

Servlet:

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

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


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

解决方案

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.

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

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