Http status 302 解惑

本文详细解析了HTTP状态码302 Found的含义及其应用场景,特别关注了Location头字段的作用,并讨论了在实际环境中如何处理带有额外斜杠('/')的重定向URL。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

302 的标准解释为:

10.3.3 302 Found

The requested resource resides temporarily under a different URI. Since the redirection might be altered on occasion, the client SHOULD continue to use the Request-URI for future requests. This response is only cacheable if indicated by a Cache-Control or Expires header field.

The temporary URI SHOULD be given by the Location field in the response. Unless the request method was HEAD, the entity of the response SHOULD contain a short hypertext note with a hyperlink to the new URI(s).

If the 302 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.

 

按照协议规定,应该在根据response中的header中的location的值重新发起一次请求。

 

实际发生时,我们的情景是:

url中参数之前的host部分没有以“/”结尾,返回的header中location添加了“/”。

比如请求url: http://192.168.1.111/client?key=123, 返回中的location为 http://192.168.1.111/client/?key=123

此时,要么按照协议,重新请求;要么请求时都加上“/”。

 

环境 nginx

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值