private Button button;
@Override
protected void onCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button)findViewById(R.id.button);
Buttonlist buttonlist =new Buttonlist();
button.setOnClickListener(buttonlist);
}
class Buttonlist implements OnClickListener{
@Override
public void onClick(View v){
Threads t=newThreads();
t.start();
}
}
class Threads extends Thread{
public void run(){
//创建HttpClient
HttpClienthttpclient=new DefaultHttpClient();
//创建代表请求的对象,参数是访问的服务器地址
HttpGethttpgrt=new HttpGet("http....");
//执行请求,获取服务器发还的相应对象
try {
HttpResponseresp = httpclient.execute(httpgrt);
//检查相应的状态是否正常,检查状态码的值是否等于200
intcode =resp.getStatusLine().getStatusCode();
if(code==200){
//相应对象中取出数据
HttpEntityentity=resp.getEntity();
InputStreamin= entity.getContent();
BufferedReaderreader=new BufferedReader(new InputStreamReader(in));
Stringline = reader.readLine();
Log.d("HTTP","从服务器去的数据"+line);
}
} catch(Exception e) {
//TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
private Button button;
@Override
protected void onCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button)findViewById(R.id.button);
Buttonlist buttonlist =new Buttonlist();
button.setOnClickListener(buttonlist);
}
class Buttonlist implements OnClickListener{
@Override
public void onClick(View v){
Threads t=newThreads();
t.start();
}
}
class Threads extends Thread{
public void run(){
//创建HttpClient
HttpClienthttpclient=new DefaultHttpClient();
//创建代表请求的对象,参数是访问的服务器地址
HttpGethttpgrt=new HttpGet("http....");
//执行请求,获取服务器发还的相应对象
try {
HttpResponseresp = httpclient.execute(httpgrt);
//检查相应的状态是否正常,检查状态码的值是否等于200
intcode =resp.getStatusLine().getStatusCode();
if(code==200){
//相应对象中取出数据
HttpEntityentity=resp.getEntity();
InputStreamin= entity.getContent();
BufferedReaderreader=new BufferedReader(new InputStreamReader(in));
Stringline = reader.readLine();
Log.d("HTTP","从服务器去的数据"+line);
}
} catch(Exception e) {
//TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}
private Button button;
@Override
protected void onCreate(BundlesavedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button=(Button)findViewById(R.id.button);
Buttonlist buttonlist =new Buttonlist();
button.setOnClickListener(buttonlist);
}
class Buttonlist implements OnClickListener{
@Override
public void onClick(View v){
Threads t=newThreads();
t.start();
}
}
class Threads extends Thread{
public void run(){
//创建HttpClient
HttpClienthttpclient=new DefaultHttpClient();
//创建代表请求的对象,参数是访问的服务器地址
HttpGethttpgrt=new HttpGet("http....");
//执行请求,获取服务器发还的相应对象
try {
HttpResponseresp = httpclient.execute(httpgrt);
//检查相应的状态是否正常,检查状态码的值是否等于200
intcode =resp.getStatusLine().getStatusCode();
if(code==200){
//相应对象中取出数据
HttpEntityentity=resp.getEntity();
InputStreamin= entity.getContent();
BufferedReaderreader=new BufferedReader(new InputStreamReader(in));
Stringline = reader.readLine();
Log.d("HTTP","从服务器去的数据"+line);
}
} catch(Exception e) {
//TODO 自动生成的 catch 块
e.printStackTrace();
}
}
}