Android http请求
来源:互联网 发布:php oa系统源码 编辑:程序博客网 时间:2024/06/06 07:47
android http请求其实很简单,这里我就不多废话了,直接上代码
重点内容
public class HttpUtil {
public static String Path_url = "http://192.168.1.109:8080/DrawServer/servlet/Draw?";public static String Path_url_login = "http://192.168.1.109:8080/DrawServer/servlet/Login?";public HttpUtil() { // TODO Auto-generated constructor stub}public synchronized static String getConnection(String path) { //path为需要访问的url //http://192.168.1.109:8080/DrawServer/servlet/Draw? URL url = new URL(path); //System.out.println("paht == " + path); HttpURLConnection connection = (HttpURLConnection) url .openConnection(); connection.setConnectTimeout(3000);//设置连接超时 connection.setRequestMethod("GET");//设置请求方式 connection.setDoInput(true); int code = connection.getResponseCode();//获得请求码,每个请求码代表网上都可以查到,如果是200就是请求成功 // System.out.println("----Code-->> " + code); if (code == 200) { return changeInPutStream(connection.getInputStream());//获取inputsteam,读取数据 } } catch (MalformedURLException e) { // TODO Auto-generated catch block System.out.println("------>> URL "); } catch (IOException e) { // TODO Auto-generated catch block System.out.println("------>> connection "); } return "";}private String changeInPutStream(InputStream inputStream) { // TODO Auto-generated method stub String JsonString = ""; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); int len; byte[] data = new byte[1024]; try { while ((len = inputStream.read(data)) != -1) { outputStream.write(data, 0, len); } JsonString = new String(outputStream.toByteArray(), "UTF-8"); } catch (IOException e) { // TODO Auto-generated catch block System.out.println("------>> outputStream "); } return JsonString;}
}
0 0
- android http post请求
- android 实现http请求
- 【Android】Http请求
- android 实现http请求
- Android Http请求
- android http请求
- Android封装Http请求
- android http 请求方式
- 【Android】Http请求
- Android HTTP请求处理
- android http请求
- Android http请求代码
- android发送http请求
- Android Http 异步请求
- [Android]http请求
- android http请求
- android http请求(1)
- Android http 请求
- 在 JavaScript 中 prototype 和 __proto__ 有什么区别
- 如何用 MAC Address 找到 IP
- Oracle触发器抛出自定义异常
- vsftp上传文件出现553 Could not create file解决方法
- 第四届河南省ACM 序号互换 进制转换
- Android http请求
- 安卓开发:webapp 打电话,发短信时的代码设置
- 二叉树遍历(非递归)
- CCF CSP试题 201609-2 火车购票
- Servlet进阶API---过滤器Filter
- [BZOJ 1030][JSOI2007]文本生成器(AC自动机+DP)
- Unity四元组Quaternion常用方法
- 漫步数学分析三十七——极大值与极小值
- ubuntu系统及软件安装相关知识