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方法结束
});// 线程结束
查看全文
相关阅读:
Boot-Repair&usb_repair
Introducing ASLR for FreeBSD
node.js操作Cookie
Docker常见仓库MySQL
Docker常见仓库CentOS
Docker常见仓库Ubuntu
Docker常见仓库Node.js
Docker常见仓库WordPress
Docker常见仓库Nginx
Docker命令查询
原文地址:https://www.cnblogs.com/maxma/p/9169620.html
最新文章
CodeForces Gym 100685J Just Another Disney Problem (STL,排序)
POJ 1470 Closest Common Ancestors (LCA)
HDU 2586 How far away ? (LCA,Tarjan, spfa)
CodeForces Gym 100685I Innovative Business (贪心)
CodeForces Gym 100685E Epic Fail of a Genie (贪心,控制精度)
CodeForces Gym 100685C Cinderella (水题)
CodeForces 711D Directed Roads (DFS判环+计数)
CodeForces 711C Coloring Trees (DP)
CodeForces 711B Chris and Magic Square (暴力,水题)
CodeForces 711A Bus to Udayland (水题)
热门文章
如何做好业务
AutoFac
看不懂的文章
算法资料
学习iis工作原理
微软重建社区
crc
Windows Server AppFabric
如何学习-维果茨基
java的arrayCopy用法
Copyright © 2011-2022 走看看