【发布时间】:2011-08-22 02:44:21
【问题描述】:
我尝试从特定的url下载图片,首先我使用这种方式获取InputStream:
if (url != null) {
URLConnection ucon = null;
try {
ucon = url.openConnection();
} catch (IOException e2) {
e2.printStackTrace();
}
if (ucon != null) {
ucon.setConnectTimeout(CONN_TIMEOUT);
ucon.setReadTimeout(READ_TIMEOUT);
try {
is = ucon.getInputStream();
效果很好,但是当我尝试从http://111.12.12.232/images/face/bigface/339.gif 下载图片时 我无法获取 InputStream,但尝试使用:
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, "UTF-8");
HttpProtocolParams.setUseExpectContinue(params, false);
HttpConnectionParams.setConnectionTimeout(params, CONN_TIMEOUT);
HttpConnectionParams.setSoTimeout(params, READ_TIMEOUT);
HttpGet getRequest;
try {
getRequest = new HttpGet(url.toURI());
HttpClient client = new DefaultHttpClient(params);
HttpResponse response = client.execute(getRequest);
HttpEntity entity = response.getEntity();
is = entity.getContent();
这样可以成功获取InputStream,并且可以下载gif。
所以我想知道这两种方法有什么不同? 谢谢~
【问题讨论】:
标签: android inputstream