I figured it out. For those experiancing the same issue, you have to
set the header for the HttpGet before sending the request. This
solved my issue.
httpget.setHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT
5.1; en-US; rv:1.8.1.20) Gecko/20081217 Firefox/2.0.0.20")
On Jul 19, 10:26 pm, Eric Crump <[email protected]> wrote:
> I am trying to download files in my application. The functionality
> has worked for many phones until now. The Evo will not download the
> files. My following code works on the Nexus 1, Droid, etc, but not
> the Evo. There is never anything in the entity.getContent()
>
> For downloading images:
>
> HttpClient httpclient = new DefaultHttpClient();
> URI uri = new URI(url);
> HttpGet getter = new HttpGet(uri);
>
> HttpResponse r = httpclient.execute(getter);
> b = BitmapFactory.decodeStream(r.getEntity().getContent());
>
> For downloading any file:
>
> URI uri = new URI(url);
> HttpGet httpget = new HttpGet(uri);
> Log.i("blah", url);
>
> response = httpclient.execute(httpget);
>
> Header [] headers = response.getAllHeaders();
> for(Header header : headers){
> Log.i("blah", header.getName() + " " +
> header.getValue());
> }
> Log.i("blah", "Header length: " + headers.length);
> Log.i("blah", "reason: " +
> response.getStatusLine().getReasonPhrase());
> Log.i("blah", "status code: " +
> response.getStatusLine().getStatusCode());
>
> HttpEntity entity = response.getEntity();
>
> if (entity != null) {
> InputStream instream = entity.getContent();
>
> File root = Environment.getExternalStorageDirectory();
>
> File f=new File(root, "/TBSA/" + filename);
> OutputStream out=new FileOutputStream(f);
> byte buf[]=new byte[1024];
> int len;
> while((len=instream.read(buf))>0){
> Log.i("blah", "read bytes");
> out.write(buf,0,len);
> }
> out.close();
>
> instream.close();
> }
>
> In the second section of code, the response is OK and the code is
> 200. When I download an MS Word file, there are 8 headers, including
> one that says Content-Type application/msword.
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en