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方法结束
});// 线程结束
查看全文
相关阅读:
【python】Python 资源大全中文版
获取最新chromedriver.exe的方法,并查阅最新的chromedriver.exe支持到什么chrome版本
appium 重新启动apk
git 命令操作
[转]IDEA 出现编译错误 Multi-catches are not supported a this language level 解决方法
jmeter压测前清理内存
清理kafka zookeeper
windows 自动移动maven jar包到jmeter 文件夹下面
jmeter 压测duobbo接口,施压客户端自己把自己压死了
kafak manager + zookeeper + kafka 消费队列快速清除
原文地址:https://www.cnblogs.com/maxma/p/9169620.html
最新文章
深度神经网络直观解释(多图)
Linux 网络流量查看 Linux ip traffic monitor
机器学习与深度学习核心知识点总结
变换矩阵 及 可视化
C# 配置错误定义了重复的“system.web.extensions/scripting/scriptResourceHandler”节
微信电脑版 1.1版,很好用
C# 出现base-64 字符数组的无效长度的解决办法
SqlServer添加触发器死锁的原因
C# 关闭进程的时候总是捕捉到System.Threading.ThreadAbortException: 正在中止线程
在电脑上查看小米手机连接wifi时保存的密码
热门文章
C# 通过api函数GetPrivateProfileString读取ini文件,取不到值
限流的简单使用及学习
Arrays.asList中所遇到的坑
JSON.toJSONString中序列化空字符串遇到的坑
由初始化线程池引发的NoClassDefFoundError 异常分析
SpringBoot actuator 应用监控。
【转载】Spring @Async 源码解读。
Feign请求中报错:Request header is too large 的解决方案。
SpringBoot自定义序列化的使用方式--WebMvcConfigurationSupport
使用OkHttpClient处理json请求处理的方式
Copyright © 2011-2022 走看看