Android 通过 HttpClient 获取网络资源

来源:互联网 发布:deb文件安装到linux 编辑:程序博客网 时间:2024/06/05 14:15

Android通过HttpClient获取网络资源已经过时了吗?

如:获取网络中的一张图片。

Class HttpUtil{public byte[] getImageByHttpClient(String imagePath){byte[] by = null;HttpClient httpClient = new DefaultHttpClient();HttpGet httpGet = new HttpGet(imagePath);try{HttpResponse httpResponse = httpClient.execute(httpGet);if(httpResponse.getStatusLine().getStatusCode==200){by=EntityUtils.toByteArray(httpResponse.getEntity());}}catch(Exception e){e.printStaticTrace();}return by;}}

0 0
原创粉丝点击