Is it possible to set some http headers while http-redirect(302 or 307)?

只谈情不闲聊 提交于 2019-12-13 13:11:09

问题


Is it possible to set some http headers while http-redirect(302 or 307)?

<?
 header("some-header: xxx");
 header("Location: http://other.domain.com/foo.php",TRUE,307);

?>

回答1:


You can basically set whatever http headers you want either as the server or the client.

If you are indicating a redirect you should supply the Location header as your example suggests. You should also ensure that your response headers refer to that response rather than the resource that the client is being redirected to. i.e. your headers here could include Content-Length: 0, omit the Content-Type header and so on.

Not sure if this is what you're after - this question could do with a bit more detail.




回答2:


You can always do the redirection 301/307. There are ways to do it 1) Do it through java code :

response.setStatus(307);
response.setHeader("Location",url);

2) THe same thing can be done in JSPs.

A tip here is: Always use the setHeader function and not the addHeader function as they behave in different ways.



来源:https://stackoverflow.com/questions/6235142/is-it-possible-to-set-some-http-headers-while-http-redirect302-or-307

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!