How do I find where an HttpURLConnection is trying to redirect me to?

久未见 提交于 2019-12-11 01:05:07

问题


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?


回答1:


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




回答2:


First turn of redirect follows:

conn.setInstanceFollowRedirects(false);

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



来源:https://stackoverflow.com/questions/9591511/how-do-i-find-where-an-httpurlconnection-is-trying-to-redirect-me-to

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