У меня не работает загрузка файлов
У меня есть ссылка https://www.pivotaltracker.com/file_attachments/47755990/download чтобы загрузить файл docx. Когда я нажимаю этот URL в файле браузера, загруженном для меня должным образом, но когда я пытаюсь загрузить его с помощью кода Android, он не работает для меня. Мой код указан ниже
public JSONObject postRequest(String url) {
OutputStream output;
InputStream inputStream = null;
String result = "";
JSONObject response = null ;
File file = null;
HttpResponse httpResponse;
try {
String directoryPath = "SirConrad";
File newFolder = new File(Environment.getExternalStorageDirectory(), directoryPath);
if (!newFolder.exists()) {
newFolder.mkdir();
}
try {
file = new File(newFolder, "sachsd.docx");
file.createNewFile();
} catch (Exception ex) {
System.out.println("ex: " + ex);
}
HttpClient httpclient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("accessToken","29c1322d3072d8fadbf2478c61fb6ff6");
httpGet.addHeader("content_type","application/vnd.openxmlformats-officedocument.wordprocessingml.document");
//httpGet.addHeader("UserID", "4");
httpResponse = httpclient.execute(httpGet);
// 9. receive response as inputStream
inputStream = httpResponse.getEntity().getContent();
output = new FileOutputStream(file);
byte data[] = new byte[4096];
long total = 0;
int count;
while ((count = inputStream.read(data)) != -1) {
output.write(data, 0, count);
}
} catch (Exception e) {
Log.d("InputStream", e.getLocalizedMessage());
}
// 11. return result
return response;
}
PS Ссылка http://pp.sirconrad.com/img/EDDYAdminPanelDesignBreakdown.docx работает для меня, чтобы загрузить вложение в приведенном выше коде, но.
Примечание * Я использую apis Pivotal Traker для загрузки этого файла.