code_junkie

Download xml.gz file with HttpsURLConnection

Nov 11th, 2011
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. URL server = new URL("https://www.myurl.com/path/sample_file.xml.gz");
  2. HttpsURLConnection connection = (HttpsURLConnection)server.openConnection();
  3. connection.connect();
  4.  
  5. if (connection.getResponseCode() == 302 && connection.getHeaderField("location") != null){
  6. URL server2 = new URL(connection.getHeaderField("location"));
  7. HttpURLConnection connection2 = (HttpURLConnection)server2.openConnection();
  8. connection2.connect();
  9. InputStream in = connection2.getInputStream();
  10. }
Add Comment
Please, Sign In to add comment