Can I download files like PDF using HttpClient?

I found some examples here on how to upload a file, but most of them seem to use HttpURLConnection. Can I upload files using HttpClient?

+7
source share
2 answers

Using httpclient is pretty simple. Here is a link to it.

http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html#d5e43

HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(urltofetch); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); if (entity != null) { long len = entity.getContentLength(); InputStream inputStream = entity.getContent(); // write the file to whether you want it. } 
+19
source

What you can do with HttpURLConnection , you can usually do better by using HttpClient view your file transfer examples and you will see how.

+1
source

All Articles