emi*_*hem 0 forms redirect http node.js
当用户提交application/x-www-form-urlencoded的表单并且我的网页收到它时,它会将用户重定向到另一个URL.问题是webbrowser不会再次将application/x-www-form-urlencoded发送到新的url.
有没有办法强制webbrowser再次发送application/x-www-form-urlencoded?
function redirectTo(request, response, site){
try {
response.writeHead('302', {'Location': site});
console.log("redirecting to " + site);
}
} catch(ex) {
// the headers were already sent - we can't redirect them
console.error("Failed to send redirect", ex);
}
response.end();
}
Run Code Online (Sandbox Code Playgroud)
这是代码.
您发布的代码不会在服务器上执行重定向,而是返回302响应,该响应指示浏览器根据新位置重定向.当浏览器执行此操作时,它会执行GET请求,而不是POST.这在第一批浏览器中是一个糟糕的实现,但由于向后兼容性仍然如此.引入了新的响应代码(307,308),它强制浏览器保留初始请求的类型.
该application/x-www-form-urlencoded只适用于POST请求,这就是为什么不保留它.
您可以在维基百科上阅读更多相关信息:http://en.wikipedia.org/wiki/HTTP_302
| 归档时间: |
|
| 查看次数: |
855 次 |
| 最近记录: |