网络请求
2015-09-07 21:19
531 查看
//自定义函数
public void getYanZhengMa(String url1) {final String url = url1;
new Thread() {//新起线程实现网络请求
public void run() {
// 响应
HttpResponse mHttpResponse = null;
// 实体
HttpEntity mHttpEntity = null;
// 生成一个请求对象
HttpGet httpGet = new HttpGet(url);
// 生成一个Http客户端对象
HttpClient httpClient = new DefaultHttpClient();
// 下面使用Http客户端发送请求,并获取响应内容
InputStream inputStream = null;
try {
// 发送请求并获得响应对象
mHttpResponse = httpClient.execute(httpGet);
// 获得响应的消息实体
mHttpEntity = mHttpResponse.getEntity();
// 获取一个输入流
inputStream = mHttpEntity.getContent();
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(inputStream));
String result = "";
String line = "";
while (null != (line = bufferedReader.readLine())) {
result += line;
}
// 将结果打印出来,可以在LogCat查看
System.out.println(result);
} catch (Exception e) {
System.out.println("chu cuo ");
}
};
}.start();
}
相关文章推荐
- Http请求超时的一种处理方法
- 关于淘宝橱窗推荐-->用户行为追踪--http协议深入
- tcp的Nagle算法
- 网络编程之socket、epoll
- TCP四种定时器
- java下tcp的socket连接
- HTTP响应报文与工作原理详解(转)
- 记录一个查询颜色RGB和HSV值还有HTTP状态码等的网站
- ab源码分析 (2013-07-12 13:00:06) http://blog.sina.com.cn/s/blog_999d1f4c0101e18f.html
- apache ab 输出结果详细解析(源码分析) http://my.oschina.net/lubia/blog/177186
- Cocos2dx引擎笔记——HttpClient session
- TestUrlHttpConnection
- TCP/IP,http,socket,长连接,短连接——小结。
- Cocos2dx引擎笔记——如何使用HttpClient
- 快速Android开发系列网络篇之Retrofit, Retrofit OKHttp GSON
- CentOS下使用tcpdump网络抓包用
- linux安装apache的纠结过程 http://www.cnblogs.com/fnng/archive/2012/08/30/2662984.html
- TCP标志位之RST
- 网络编程
- ioS开发之网络--网络基础概况