是否可以使用HttpClient下载PDF之类的文件? [英] Is it possible to download files like PDF with HttpClient?
本文介绍了是否可以使用HttpClient下载PDF之类的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在这里找到了一些有关如何下载文件的示例,但是其中大多数似乎都在使用HttpURLConnection.可以使用HttpClient下载文件吗?
I found some examples here on how to download a file but most of them seem to be using HttpURLConnection. is it possible to download files with HttpClient?
推荐答案
使用httpclient非常简单.这是它的教程的链接.
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.
}
这篇关于是否可以使用HttpClient下载PDF之类的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文