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设置出错信息 }
下载说明:请别用迅雷下载,失败请重下,重下不扣分!