2013年9月12日星期四

Call url.openConnection (). GetInputStream () Download Times java.io.IOException

 This post last edited by the ppmmwozuiai on 2013-09-12 16:36:07
error message the first two lines are:
java.io.IOException: Server returned HTTP response code: 401 for URL: http://localhost/jsp/downloadtmp/126806114/6.zip
at sun.net.www.protocol.http.HttpURLConnection.getInputStream (Unknown Source)

Code:

			try {
URL url = new URL(BASE_URL + requestNumber + "/" + fileName);
File outFile = new File(path + File.separator + fileName);
os = new FileOutputStream(outFile);
is = url.openConnection().getInputStream();
byte[] buff = new byte[1024];
while (true) {
int readed = is.read(buff);
System.out.println("--------------" + buff.length);
if (readed == -1) {
break;
}
byte[] temp = new byte[readed];
System.arraycopy(buff, 0, temp, 0, readed);
os.write(temp);
}

} catch (Exception e) {
e.printStackTrace();
} finally {
try {
is.close();
os.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}


not understand why the fifth line of the error. .
------ Solution ---------------------------------------- ----
Server returned HTTP response code: 401
only know 401 404 do not know , ah
------ Solution ------------------------- -------------------
right. Should set the authentication /
------ For reference only --------------------------------- ------
I understand. Website authentication. Before the call must present a certified job.

没有评论:

发表评论