HTTPURLConnection Doesn’t Follow Redirect from HTTP to HTTPS

Redirects are followed only if they use the same protocol. (See the followRedirect() method in the source.) There is no way to disable this check.

Even though we know it mirrors HTTP, from the HTTP protocol point of view, HTTPS is just some other, completely different, unknown protocol. It would be unsafe to follow the redirect without user approval.

For example, suppose the application is set up to perform client authentication automatically. The user expects to be surfing anonymously because he’s using HTTP. But if his client follows HTTPS without asking, his identity is revealed to the server.

Leave a Comment