我不能用基本的http-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来完成这个任务,但也得到了异常。
发布于 2015-08-27 14:00:02
正如我所评论的,您应该删除行setDoOutput(true),因为这是GET请求。
https://stackoverflow.com/questions/32246613
复制相似问题