Forums de discussion

How to download a file from HTTPS url

Logu R, modifié il y a 7 années.

How to download a file from HTTPS url

New Member Publications: 10 Date d'inscription: 15/05/15 Publications récentes
How to download a file from HTTPS server using Java. Am getting , am getting HTTPS Response Code : 401, can someone assist on this.
thumbnail
Olaf Kock, modifié il y a 7 années.

RE: How to download a file from HTTPS url

Liferay Legend Publications: 6403 Date d'inscription: 23/09/08 Publications récentes
HTTP 401 means "Unauthorized". If that doesn't help you: We have no clue what system you're requesting data from. That means nobody can tell you how to authenticate and authorize without more information
Logu R, modifié il y a 7 années.

RE: How to download a file from HTTPS url

New Member Publications: 10 Date d'inscription: 15/05/15 Publications récentes
Thank you for the reply.

Now, i able to pass the authentication and able to downlaod the file also.
But the problem is not able to view the file, i mean files get downloaded with 3 kb but actual size is 260 kb.

Please find the code below

url = new URL(fileURL);
con = url.openConnection();
con.setRequestProperty ("Authorization", "Basic " + loginPassword);
InputStream is = con.getInputStream();
OutputStream os = new FileOutputStream(saveDir);

while ((i = is.read()) != -1) {
os.write(BUFFER_SIZE,0,i);
//System.out.println("file downloaded");
}