HttpURLConnection和Httpclient get请求
来源:互联网 发布:wampserver绑定域名 编辑:程序博客网 时间:2024/04/30 00:35
protected void endreauest() {
// TODO Auto-generated method stub
new Thread(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
try {
String key="19f0b2ebeec053b333acaca294186851";
//String s=ee.getText().toString();
//http://op.juhe.cn/onebox/news/query?key=&q=%E6%99%AE%E4%BA%AC%E5%A4%B1%E8%B8%AA
URL url=new URL("http://op.juhe.cn/onebox/news/query?key="+key+"&q="+URLEncoder.encode(ee2)+"&dtype");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setConnectTimeout(8000);
connection.setReadTimeout(5000);
InputStream stream = connection.getInputStream();
BufferedReader reader=new BufferedReader(new InputStreamReader(stream));
final StringBuilder builder=new StringBuilder();
String line;
while((line=reader.readLine())!=null){
builder.append(line);
//Log.i("list", builder.toString());
Gson g=new Gson();
String str=builder.toString();
New fromJson = g.fromJson(str, New.class);
fromJson.getError_code();
fromJson.getReason();
list = fromJson.getResult();
Log.i("list", list.toString());
}
runOnUiThread(new Runnable() {
public void run() {
//t1.setText(builder);
adapter = new Myadapter(MainActivity.this,list);
li.setAdapter(adapter);
}
});
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}).start();
}
private String getjson(String url) {
String str=null;
try {
HttpClient client=new DefaultHttpClient();
HttpGet get=new HttpGet(url);
HttpResponse response=client.execute(get);
int statusCode = response.getStatusLine().getStatusCode();
if(statusCode==200){
HttpEntity entity = response.getEntity();
str = EntityUtils.toString(entity, "UTF_8");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
private String getjson(String url) {
String str=null;
try {
HttpClient client=new DefaultHttpClient();
HttpGet get=new HttpGet(url);
HttpResponse response=client.execute(get);
int statusCode = response.getStatusLine().getStatusCode();
if(statusCode==200){
HttpEntity entity = response.getEntity();
str = EntityUtils.toString(entity, "UTF_8");
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
1 0
- HttpURLConnection和Httpclient get请求
- httpurlconnection 和 httpclient 发送get、post请求
- HttpClient和HttpURLConnection请求
- HttpUrlconnection 、Httpclient get 、post 请求核心代码
- AsyncHttpClient 、HttpURLConnection get/post请求、httpClient
- 【Java】HttpURLConnection,HttpClient 的 Get,Post 请求
- 使用HttpURLConnection和使用HttpClient方式请求网络采用get方式和post方式请求数据
- HttpUrlConnection和HttpClient和android-async-http框架的GET和POST请求
- HttpUrlConnection post和get请求
- HttpURLconnection/get和post请求
- Android中使用HttpURLConnection和HttpClient实现GET和POST请求访问网络
- android(21)(使用HttpURLConnection,HttpClient和AsyncHttpClient分别实现post和get请求数据)
- HttpUrlConnection和HttpClient两种方式获取GET和POST请求
- get和post请求(HttpUrlConnection、HttpClient、AsyncHttpClient)多线程下载,断点续传
- httpUrlConnection用于post请求和get请求
- httpUrlConnection用于post请求和get请求
- HttpUrlConnection的GET请求和POST请求
- httpurlconnection的Get请求和Post请求
- androidstudio开发工具下载
- Toast
- 教你如何抢救丢失的文稿
- html链接到页面指定位置
- Xcode 7中http通信出现如下错误
- HttpURLConnection和Httpclient get请求
- Android开发之armeabi
- POJ 1328 Radar Installation
- 笔试题67. LeetCode OJ (54)
- Android 设计模式 之 单例模式
- 借助Gson解析Json的方法
- 序列式容器:vecor,stack,queue用法
- Hive基本操作
- 如何进行finetune