HttpURLConnection工具类 获取图片+Json
来源:互联网 发布:java自学还是培训 编辑:程序博客网 时间:2024/06/17 12:45
//获取图片
public Bitmap getNetImage(String urlstring){ try { URL url=new URL(urlstring); HttpURLConnection urlConnection= (HttpURLConnection) url.openConnection(); int responseCode = urlConnection.getResponseCode(); if(responseCode==200){ InputStream inputStream = urlConnection.getInputStream(); Bitmap bitmap = BitmapFactory.decodeStream(inputStream); return bitmap; }else { Log.e("ZKF","responseCode"+responseCode); } } catch (Exception e) { e.printStackTrace(); } return null;}//请求字符串public String getNetString(String urlstring){ try { URL url=new URL(urlstring); HttpURLConnection urlConnection= (HttpURLConnection) url.openConnection(); int responseCode = urlConnection.getResponseCode(); if(responseCode==200){ InputStream inputStream = urlConnection.getInputStream(); BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(inputStream)); StringBuilder stringBuilder=new StringBuilder(); String stringTemp=""; while((stringTemp=bufferedReader.readLine())!=null){ stringBuilder.append(stringTemp); } String result = stringBuilder.toString(); Log.e("ZKF","请求的字符串"+result); return result; }else { Log.e("ZKF","responseCode"+responseCode); } } catch (Exception e) { e.printStackTrace(); } return null;}
阅读全文
0 0
- HttpURLConnection工具类 获取图片+Json
- HttpURLConnection获取JSON处理
- HttpURLConnection获取网络数据工具类
- HttpURLConnection获取网络图片
- HttpURLConnection获取图片数据流
- HttpURLConnection 获取图片
- HttpUrlConnection获取网络json串
- 获取图片工具类
- 封装的工具类(网络获取Json,图片,下载图片,下载Mp3,下载视频)
- Android通过HttpURLConnection类进行网络通信,获取网络图片
- Android通过HttpURLConnection类进行网络通信,获取网络图片!!!
- Android通过HttpURLConnection类进行网络通信,获取网络图片
- HttpURLConnection工具类
- 自定义HttpURLConnection工具类
- HttpURLConnection和HttpClient获取Json数据
- HttpURLConnection和HttpClient获取Json数据
- Android HttpURLConnection数据获取并JSON解析
- Android用HttpURLConnection获取JSON数据
- 数据库 增删改查
- docker系列文章
- HDU 4666 Hyperspace
- 设计模式(13)--Chain of Responsibility(责任链模式)--行为型
- 大话设计模式之六:11~15章(迪米特法则 、外观模式、建造者模式、观察者模式、抽象工厂模式)
- HttpURLConnection工具类 获取图片+Json
- 第一次博客
- 决策树算法---概念
- (学习笔记)设计模式之状态模式(游戏场景切换)
- 使用<c:forEach>标签遍历List中的map元素
- 负载均衡基础知识
- AsyncTask 网络获取图片和Json数据加载到ListView上
- MySql deadlock
- Nuttx下新建路径以及motors