获取头条
来源:互联网 发布:firefox 调试js 编辑:程序博客网 时间:2024/04/28 17:47
/**
* 网络上获取头条的数据
*/
private void getTouTiao() {
new Thread(){
@Override
public void run() {
try {
URL url = new URL("http://www.toutiao.com/hot_words/");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
//设置
connection.setRequestMethod("GET");
connection.setReadTimeout(5000);
connection.setConnectTimeout(5000);
connection.setRequestMethod("GET");
connection.setReadTimeout(5000);
connection.setConnectTimeout(5000);
//获取
int responseCode = connection.getResponseCode();
if (responseCode == 200){
InputStream inputStream = connection.getInputStream();
int responseCode = connection.getResponseCode();
if (responseCode == 200){
InputStream inputStream = connection.getInputStream();
//将字节流装换为字符串
String json = streamToString(inputStream,"utf-8");
String json = streamToString(inputStream,"utf-8");
//字符串发送到主线程解析
Message message = Message.obtain();
message.what = 0;
message.obj = json;
handler.sendMessage(message);
Message message = Message.obtain();
message.what = 0;
message.obj = json;
handler.sendMessage(message);
}
} catch (Exception e) {
e.printStackTrace();
}
e.printStackTrace();
}
}
}.start();
}.start();
}
阅读全文
0 0
- 获取头条
- 简单今日头条数据获取
- 头条
- C# WebApi 获取今日头条新闻代码
- 获取今日头条西瓜视频下载地址
- @头条新闻V:
- phpcms头条图片
- 头条新闻
- 程序员头条
- 今日头条算法
- 面试-今日头条
- 今日头条
- 今日头条
- 今日头条
- 今日头条面试
- 今日头条导航
- 仿今日头条
- 今日头条笔试
- Python(基础)第二天
- dataTable的使用总结
- "LPWSTR" 类型的值不能用于初始化 "char *" 类型的实体
- cxf-Springmvc-maven实现webservice
- 判断文件是否存在的shell脚本代码
- 获取头条
- 数据库的ACID特性解释
- 20171009有感
- linux-telnet
- Codeforces 320C Malek Dance Club【规律】
- 【poj 1330】 Nearest Common Ancestors 【Taejon 2002】
- DrawerLayout抽屉更新MainActivity的viewpager
- Windows根据程序标题查找正在运行的程序的HWND--判断窗口程序是否运行
- 手机号判断ios