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方法结束
});// 线程结束
查看全文
相关阅读:
tp5更改入口文件到根目录的方法分享
Linux安装JBOSS
JBOSS和WebLogic区别
面向对象编程的思维方式
Struts+Spring+Hibernate整合入门详解
DB2 UDB V8.1 管理
oracle与DB2的一些架构
oracle和DB2的差异
JDK和JRE的区别
Linux安装weblogic
原文地址:https://www.cnblogs.com/maxma/p/9169620.html
最新文章
apache服务器—虚拟目录+虚拟主机
linux学习笔记——文字
常用正则表达式
java解析Excel(兼容2003及2007)
[转载]Frontend Knowledge Structure
[转载]Web API OData Inlinecount not working
[转载]Supporting OData $inlinecount with the new Web API OData preview package
[转载]AngularJS and scope.$apply
[转载]JavaScript异步编程助手:Promise模式
[转载]Windows 8 VHD 概述与使用
热门文章
[转载]Cross-Platform Development in Visual Studio
[转载]VS2013 密钥 – 所有版本
[整理]Git使用文章整理
lamp 环境利用compser安装tp5
如何在Linux上安装Composer
linux开启数据库远程连接
linux出现Redirecting to /bin/systemctl start mysqld.service,解决方法
忘记Linux 3.X/4.x/5.x 宝塔面板密码的解决方案
阿里云服务器ECS装好宝塔 但访问不了面板的解决方法
TP-四种url访问的方式
Copyright © 2011-2022 走看看