I am trying to download the xml.gz file from a remote server using HttpsURLConnection in java, but I get an empty answer. Here is an example of my code:
URL server = new URL("https://www.myurl.com/path/sample_file.xml.gz");
HttpsURLConnection connection = (HttpsURLConnection)server.openConnection();
connection.connect();
When I try to get an InputStream from a connection, it is empty. (If I try connection.getInputStream (). Read () I get -1) The file I expect is approximately 50 MB.
To check my sanity, I also tried to enter the same url in my browser and it returned the file I needed. Am I missing something? Should I set some kind of parameter in the connection? Any help / direction is greatly appreciated.
source
share