Drew
Drew

Reputation: 13408

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

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?

Upvotes: 2

Views: 1114

Answers (2)

Thomas
Thomas

Reputation: 1401

First turn of redirect follows:

conn.setInstanceFollowRedirects(false);

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

Upvotes: 1

Guillaume Polet
Guillaume Polet

Reputation: 47617

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

Upvotes: 3

Related Questions