cod*_*441 7 java pdf httpurlconnection apache-commons-httpclient
我在这里找到了一些关于如何下载文件的例子,但是大多数文件似乎都在使用HttpURLConnection.是否可以使用HttpClient下载文件?
Mat*_*att 20
使用httpclient非常简单.这是教程的链接.
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.
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
18112 次 |
| 最近记录: |