HttpResponse code 302

天涯浪子 提交于 2019-12-05 12:50:24

An HTTP 302 is a 'temporary redirect'. You need to handle it.

As per the standard, if you get a 302 response, the response will contain a 'Location' header field with the redirect:

Client request:
GET /index.html HTTP/1.1
Host: www.example.com

Server response:
HTTP/1.1 302 Found
Location: http://www.redirected-address.example.com/

You need to extract the new URL from the response. (Use getHeaderField("Location") to do this). Then execute the same method on the new URL you got.

Two other points:

  1. Since this is a 'temporary' redirect, you cannot store this new URL. You should keep using the old one, and if it returns a 302, then use whatever URL is in 'Location'.

  2. If you are not executing a GET or HEAD, you shouldn't do the redirect automatically. Instead ask for user intervention. The RFC requires this.

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