WEB开发网
开发学院手机开发Android 开发 Android HttpClient网络通信 阅读

Android HttpClient网络通信

 2010-07-13 21:24:00 来源:WEB开发网   
核心提示:// TODO Auto-generated catch blocke.printStackTrace();}}});new Thread(this).start();}public void refresh(){String httpUrl = "http://192.168.0.132:8080/Andr

// TODO Auto-generated catch block

e.printStackTrace();

}

}

});

new Thread(this).start();

}

public void refresh(){

String httpUrl = "http://192.168.0.132:8080/Android/httpreq.jsp";

try {

URL url = new URL(httpUrl);

HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();

urlConn.connect();

InputStream input = urlConn.getInputStream();

InputStreamReader inputreader = new InputStreamReader(input);

BufferedReader reader = new BufferedReader(inputreader);

String str = null;

StringBuffer sb = new StringBuffer();

while((str = reader.readLine())!= null){

sb.append(str).append(" ");

}

if(sb != null){

tv_rp.setText(sb.toString());

}else{

tv_rp.setText("NULL");

}

reader.close();

inputreader.close();

input.close();

reader = null;

inputreader = null;

input = null;

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

public Handler handler = new Handler(){

public void handleMessage(Message msg){

super.handleMessage(msg);

refresh();

}

};

public void run() {

// TODO Auto-generated method stub

while(true){

try {

Thread.sleep(1000);

handler.sendMessage(handler.obtainMessage());

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

package com.Aina.Android;

上一页  1 2 3 4 5 6 7 8  下一页

Tags:Android HttpClient 网络通信

编辑录入:coldstar [复制链接] [打 印]
赞助商链接