android http请求(1)
来源:互联网 发布:91手机助手mac电脑版 编辑:程序博客网 时间:2024/05/16 02:52
package com.example.simpleclient;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;import org.apache.http.HttpResponse;import org.apache.http.client.ClientProtocolException;import org.apache.http.client.HttpClient;import org.apache.http.client.methods.HttpGet;import org.apache.http.impl.client.DefaultHttpClient;import android.app.Activity;import android.os.Bundle;import android.os.Handler;import android.os.Message;import android.util.Log;import android.view.Menu;public class SimpleClient extends Activity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);test();}public void test(){final Handler myHandler = new Handler() {public void handleMessage(Message msg) {switch (msg.what) {case 1:Log.i("tag", "返回到主线程。");//System.out.println("返回到主线程了");break;}super.handleMessage(msg);}};new Thread(new Runnable() {public void run() {HttpClient client = new DefaultHttpClient(); StringBuilder builder = new StringBuilder(); HttpGet get = new HttpGet("http://www.baidu.com"); try {HttpResponse response = client.execute(get);BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); for (String s = reader.readLine(); s != null; s = reader.readLine()) { builder.append(s); } Log.i("tag", "百度返回的数据:" + builder.toString()); } catch (ClientProtocolException e) {e.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();} Message message = new Message(); message.what = 1; myHandler.sendMessage(message);}}).start();}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}
0 0
- android http请求(1)
- android http post请求
- android 实现http请求
- 【Android】Http请求
- android 实现http请求
- Android Http请求
- android http请求
- Android封装Http请求
- android http 请求方式
- 【Android】Http请求
- Android HTTP请求处理
- android http请求
- Android http请求代码
- android发送http请求
- Android Http 异步请求
- [Android]http请求
- android http请求
- Android http 请求
- hdu 4946
- 什么加值电话 声讯电话商机 月收入两万
- 手机吸费创业 怎么加盟声讯电话 快速致富
- 吸费电话加盟 手机吸费加盟 月收入过万
- 括号配对
- android http请求(1)
- Spring的IOC依赖注入实例
- android开发之解决ListView滑动时背景是黑色的问题
- 设计模式学习--Singleton
- ora-12154 tns无法解析指定的连接标示符的解决方法
- Android Afinal框架学习(二) FinalActivity 一个IOC框架
- ny 465 最大值和最小值
- mysql处理高并发,防止库存超卖
- TS数据结构分析