Android ~ send http request and get http response

if http://xxxxxxxxxx.com return "xxxxxxxxxxxxxxxxxxxxx"

then the log get tag "qqq" message "xxxxxxxxxxxxxxxxxxxxx"

---------------------------------------------------------------------------------------------------------------------

mAddAccountButton = (Button) findViewById(R.id.okButton);

mAddAccountButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://xxxxxxxxxx.com");

try {

HttpResponse response = httpclient.execute(httppost);
String temp = EntityUtils.toString(response.getEntity());

Log.i("qqq", temp);


} catch (ClientProtocolException e) {

Log.i("qqq", "bbbbbbbbbbbbbb");
} catch (IOException e) {

Log.i("qqq", "ccccccccccc");
}

}
});

---------------------------------------------------------------------------------------------------------------------

reference
http://www.androidsnippets.org/snippets/36/

沒有留言: