HTTPURLConnection Doesn't Follow Redirect from HTTP to HTTPS

后端 未结 6 478
时光取名叫无心
时光取名叫无心 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:12

    Another option can be to use Apache HttpComponents Client:

    
        org.apache.httpcomponents
        httpclient
    
    

    Sample code:

    CloseableHttpClient httpclient = HttpClients.createDefault();
    HttpGet httpget = new HttpGet("https://media-hearth.cursecdn.com/avatars/330/498/212.png");
    CloseableHttpResponse response = httpclient.execute(httpget);
    final HttpEntity entity = response.getEntity();
    final InputStream is = entity.getContent();
    

提交回复
热议问题