- class NeworkThread extents Thread{
- @Override
- public void run(){
- //创建HttpClientHttpClient httpClient =new DefaultHttpClient();
- //创建代表请求的对象,参数是访问的服务器地址HttpGet httpGet =newHttpGet("http://www.marschen.com/data1.html");
- //执行请求,获取服务器发还的相应对象HttpResponse resp = HttpClient.execute(httpGet);
- //检查响应状态是否正常,如果等于200则正常
- intcode = resp.getStatusLine().getStatusCode();
- if(code == 200){
- //从相应对象中取出数据HttpEntity entity = resp.getEntity();
- InputStream in = entity.gitContent();
- BufferedReader reader =newBufferedReader(new InputStreamReader(in));
- String line = reader.readLine();
- log.d("HTTP","从服务器取得的数据为"+line);
- }
- }
- }
来源: