HTTPURLConnection Doesn't Follow Redirect from HTTP to HTTPS

后端 未结 6 471
时光取名叫无心
时光取名叫无心 2020-11-22 10:39

I can\'t understand why Java\'s HttpURLConnection does not follow an HTTP redirect from an HTTP to an HTTPS URL. I use the following code to get the page at htt

6条回答
  •  渐次进展
    2020-11-22 11:16

    As mentioned by some of you above, the setFollowRedirect and setInstanceFollowRedirects only work automatically when the redirected protocol is same . ie from http to http and https to https.

    setFolloRedirect is at class level and sets this for all instances of the url connection, whereas setInstanceFollowRedirects is only for a given instance. This way we can have different behavior for different instances.

    I found a very good example here http://www.mkyong.com/java/java-httpurlconnection-follow-redirect-example/

提交回复
热议问题