2015-08-27 2 views
1

Я не могу скачать файл с основным http-auth. У меня есть строка auth для авторизации, но я получаю исключение: FileNotFound. Код:Загрузить файл через http-auth

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 для решения этой задачи, но получить исключение тоже.

+0

Удалить строку setDoOutput (true). – BNK

+1

Спасибо, это мне помогает) –

ответ

1

Как я уже сказал, вы должны удалить строку setDoOutput (true), потому что это запрос GET.

 Смежные вопросы

  • Нет связанных вопросов^_^