Android面HTTP协议发送get要求
2015-08-06 16:51
176 查看
/** * 采纳get办法要求 * * @param username * @param password * @return null表示求得的路径有问题,text返回请求得到的数据 */ public static String getRequest(String username, String password) { try { String path = "http://172.22.64.156:8080/0001AndroidWebService/LoginServlet?username=" + URLEncoder.encode(username) + "&password=" + URLEncoder.encode(password); URL url = new URL(path); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setReadTimeout(500); conn.setRequestMethod("GET"); int code = conn.getResponseCode(); if (code == 200) { // 请求成功 InputStream is = conn.getInputStream(); String text = StreamUtil.readStream(is); return text; } else { // 请求失败 return null; } } catch (Exception e) { e.printStackTrace(); } return null; }
相关文章推荐
- 【python网络编程】利用select实现socket全双工异步通信
- Android网络请求工具类
- 欢迎使用CSDN-markdown编辑器
- HTTP协议详解
- 怎样使用NetFlow分析网络异常流量一
- Linux IO多路复用之epoll网络编程(含源码)
- 请求网络数据的url中带有汉字的解决办法
- HTTP与HTTPS的区别
- [Java Web]Error parsing HTTP request header Note: further occurrences of HTTP header parsing errors
- TCP中的RST复位信号
- http协议分析
- HttpClient
- HTTP Basic Authentication in JMeter
- 网络协议 之 邮件协议
- 在网络通讯中应用Protobuf
- 【linux高级程序设计】(第十五章)UDP网络编程应用 3
- 黑马程序员——java高新技术——网络编程
- 【Apache学习】编译安装httpd2.4 含傻瓜版自动安装脚本
- CDN(内容分发网络)技术原理
- Qt QTcpServer/QTcpSocke