NetWorkUtils
来源:互联网 发布:2017前景行业知乎 编辑:程序博客网 时间:2024/06/05 18:52
package com.bwei.utils;import java.io.IOException;import java.io.InputStream;import java.net.HttpURLConnection;import java.net.MalformedURLException;import java.net.URL;/** * 作者: * 时间:2017/9/11 9:28 * 类描述:网络请求数据工具类 */public class NetWorkUtil { public String getStrJson(String strUrl){ URL url = null; HttpURLConnection httpURLConnection = null; String strJson = ""; InputStream inputStream = null; try { url = new URL(strUrl); httpURLConnection = (HttpURLConnection) url.openConnection(); httpURLConnection.setConnectTimeout(5000); httpURLConnection.setReadTimeout(5000); int code = httpURLConnection.getResponseCode(); if (code == 200){ byte[] bt = new byte[1024]; int length = 0; inputStream = httpURLConnection.getInputStream(); while ((length = inputStream.read(bt))!=-1){ strJson += new String(bt,0,length); } } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }finally { if (inputStream != null){ try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } return strJson; }}
阅读全文
0 0
- NetWorkUtils
- Android NetworkUtils
- android NetworkUtils
- NetworkUtils 网络相关的工具类NetworkUtils
- Wiki_Android_网络工具类NetworkUtils
- 工具类之NetworkUtils
- Android 网络工具类NetworkUtils使用
- Android 网络工具类NetworkUtils使用
- 网络请求框架封装(NetWorkUtils)
- Android 网络工具类NetworkUtils使用
- Android 网络工具类NetworkUtils使用
- Accessing a Resource over HTTP-NetworkUtils
- Android 工具类 判定有无网络 NetworkUtils
- Android的Utils工具类的NetworkUtils
- Utils包下的NetWorkUtils),解析json数据通用
- okhttp3的工具类(GsonArrayCallback GsonObjectCallback NetWorkUtils OkHttp3Utils)
- Android 实时网路监测类 步骤二(NetworkUtils 判断网络状态类)
- WindowManager: android.view.WindowLeaked
- javascript学习之this、apply、call、bind
- 那些问题的神回复(三)
- web学习笔记(一)
- 如何快速获取图片的ROI区域坐标
- NetWorkUtils
- 点击变色
- luoguP1471 方差
- Java 多态部分 向上转型 向下转型
- ImageLoader简单属性
- 集合为空与长度为零区别
- 冒泡排序
- 常用的SQL语句
- SGISTL源码探究-关联式容器:hash_set