Reputation: 12435
I'm working on application which has workflow like this:
1.parsing home page (using HttpURLConnection, connect(), do stuff, disconnect(), use data),
2.after click on links I made, parsing article or download file based on link.
First step works perfect & 2nd too in case of article, but when I'm trying to download file from specific url and save it to SD card, I got fileNotFoundException in this line:
InputStream inputStream = urlConnection.getInputStream();
My guide for doing it (downloading file) was code explained here http://goo.gl/GTBOP and I set permissions in manifest as required for this action, plus before any download operation I checked MEDIA_MOUNTED & MEDIA_MOUNTED_READ_ONLY state and it seems like that fits nice.
So..I read a lot about this problem on stackOverflow and other places and I tried different suggestions like adding these:
urlConnection.setRequestProperty("User-Agent","Mozilla/5.0 ( compatible ) ");
urlConnection.setRequestProperty("Accept","*/*");
or
System.setProperty("http.keepAlive", "false");
but with no success. I'm still stucked with fileNotFoundException. I tried to catch response code from webpage and it says 404.. ?!
It's strange that if I hardcode link to file for downloading from any other site it downloads file without any troubles. So to make it clear I pickup clicked link to fileurl variable but in a next step I just say fileurl="somesite/somefile.ext" everything goes smooth.. From web browser I can download any file that make troubles in my application so I'm confused where is the problem..
Any suggestion please..? 10q
Upvotes: 0
Views: 2069
Reputation: 12435
Oki.. after so much time no answer to this.. :( Finally I found solution on my own so I'm posting here cause somebody will hopefully find use of it..
in URL i noticed a lot %20 so before I used it I encode it with URI.encode(fileURL) as it described on android dev pages
and voila.. everything was ok.. :) Thanks everybody for contributing community! ;) Cheers
Upvotes: 4
Reputation: 28418
The 404 or Not Found error message is a HTTP standard response code indicating that the client was able to communicate with the server, but the server could not find what was requested.
So this means the only thing - your file URL was pointing to a non-existent resource. How it can be possible? I don't know. Use debugging/logging to find out where you break the url.
Upvotes: 0