zoukankan
html css js c++ java
使用HttpUrlConnection连接网络的例程
new Thread(new Runnable() {
@Override
public void run() {
String urlString = "
http://www
....";
HttpURLConnection conn = null;
try {
URL url = new URL(urlString);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setConnectTimeout(8000);
conn.setReadTimeout(8000);
InputStream in = conn.getInputStream();
// 下面对获得的输入流进行读取
BufferedReader reader = new BufferedReader(
new InputStreamReader(in));
StringBuilder sb = new StringBuilder();
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
Message msg = new Message();
msg.what = 1;
msg.obj = sb.toString();
handler.sendMessage(msg);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (conn != null)
conn.disconnect();
}
}// run方法结束
});// 线程结束
查看全文
相关阅读:
第1关:逆序输出数组元素
Ubuntu配置java环境安装JDK8
Ubuntu18安装Tomcat服务
Windows+ubuntu1803双系统安装
问题 F: 水仙花数(C#)
问题 A: C#异或运算符的使用
hdu 2642 Stars 【二维树状数组】
poj 2352 stars 【树状数组】
hdu 1698 Just a Hook 【线段树+lazy】
线段树【单点更新,区间更新,区间查询,最值查询】
原文地址:https://www.cnblogs.com/maxma/p/9169620.html
最新文章
jenkins系列---【Docker下安装Jenkins】
vue系列---【[v-cloak]解决网络卡顿时,刷新页面时显示“{{msg}}”,出现闪动的问题】
SpringCloud系列---【Hystrix熔断器】
nginx系列---【niginx的常用配置】
css系列---【如何让文字水平垂直居中?】
我爱java系列---【mysql数据库如何开启binlog日志】
Two Sum III
Lintcode: Rehashing
Isomorphic Strings + iso follow up
Contains Duplicate II
热门文章
264. Ugly Number II
Shortest Word Distance III
Shortest Word Distance II
Shortest Word Distance
Unique Word Abbreviation
Word Pattern
第5关:二维数组行列互换
第4关:十进制数转换为二进制数
第3关:求数组中的最大值和最小值
第2关:数据排序
Copyright © 2011-2022 走看看