下载链接:http://www.codesc.net/source/15744.shtml
标题:Android 创建HttpPost对象 获取HTTP连接
HttpGet httpGetRequest = new HttpGet(urlGet);//创建HttpPost对象 try { HttpResponse httpResponse = new DefaultHttpClient().execute(httpGetRequest); if(httpResponse.getStatusLine().getStatusCode()==200){//连接成功 String result = EntityUtils.toString(httpResponse.getEntity());//获得资源 result = result.replaceAll("
|
||
", "");//去掉信息中的回车和换行 EditText etGet = (EditText)findViewById(R.id.etGet);//获得EditText对象 etGet.setText(result);//为EditText设置内容 } } catch (Exception e) {//捕获并打印异常 EditText etGet = (EditText)findViewById(R.id.etGet);//获得EditText对象 etGet.setText("连接出错:"+e.getMessage());//为EditText设置出错信息 }