你需要转换
URLConnection到
HttpURLConnection并指示它不是通过设置跟随重定向
HttpURLConnection#setInstanceFollowRedirects()到
false。你还可以通过进行全局设置
HttpURLConnection#setFollowRedirects()。
然后,你只需要自己处理重定向。通过检查响应代码,通过
HttpURLConnection#getResponseCode()抓取Location标头
URLConnection#getHeaderField(),然后在其上激发一个新的HTTP请求。



