private EditText et; private TextView tv; HttpClient client; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); et=(EditText) findViewById(R.id.et); tv=(TextView) findViewById(R.id.tv); client=new DefaultHttpClient(); findViewById(R.id.btn).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { readNet("http://www.cnblogs.com/"+et.getText()); } }); } public void readNet(String url){ new AsyncTask<String, Void, String>() { @Override protected String doInBackground(String... params) { String urlString=params[0]; HttpGet get=new HttpGet(urlString); try { HttpResponse response=client.execute(get); String v=EntityUtils.toString( response.getEntity()); return v; } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; } @Override protected void onPostExecute(String result) { tv.setText(result); } }.execute(url); }
效果图 自己博客: