【发布时间】:2015-08-27 10:13:26
【问题描述】:
我无法使用基本的 http-auth 下载文件。我有用于授权的 auth 字符串,但出现异常:FileNotFound。 代码:
URL url = new URL(params[0]);
URLConnection conection = url.openConnection();
conection.setRequestProperty("Authorization", authString);
conection.setRequestMethod("GET");
conection.setAllowUserInteraction(false);
conection.setDoInput(true);
conection.setDoOutput(true);
conection.connect();
int lenghtOfFile = conection.getContentLength();
// Exception on line below
BufferedInputStream input = new BufferedInputStream(conection.getInputStream());
// Output stream
OutputStream output = new FileOutputStream(filePath);
byte data[] = new byte[1024];
...
lenghtOfFile 不为 0。此外,我尝试使用 HtppClient 执行此任务,但也出现异常。
【问题讨论】:
-
删除 setDoOutput(true) 行。
-
谢谢,对我有帮助)
标签: java android http download http-authentication