How do I find where an HttpURLConnection is trying

2019-07-19 22:47发布

I have an HttpURLConnection that I do not what to follow redirects, however if a redirect appears I want to know where I would get redirected to. There doesn't seem to be a method of HttpURLConnection that will show me that, is there any way I can get that information?

2条回答
我命由我不由天
2楼-- · 2019-07-19 23:29

Get the Header "Location", it contains the URL where you are redirected. Look at the HTTP spec for all the details

查看更多
虎瘦雄心在
3楼-- · 2019-07-19 23:47

First turn of redirect follows:

conn.setInstanceFollowRedirects(false);

conn being your HTTPConnection variable. Then read the Location header.

查看更多
登录 后发表回答