Is it possible to download files like PDF with HttpClient?

 ̄綄美尐妖づ 提交于 2019-12-03 00:31:47

Using httpclient is pretty easy. Here's a link to it's tutorial.

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.
}

Anything you can do with HttpURLConnection you can do, usually better, with HttpClient look through their examples about file transfer and you will see how.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!