Skip to content

Instantly share code, notes, and snippets.

@ducalpha
Created August 14, 2013 05:35
Show Gist options
  • Save ducalpha/6228284 to your computer and use it in GitHub Desktop.
Save ducalpha/6228284 to your computer and use it in GitHub Desktop.
HTTP request on Android
private class HTTPRequestTest extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params)
{
String url = "http://cps.kaist.ac.kr/index.html";
HttpClient httpclient = new DefaultHttpClient();
// Prepare a request object
HttpGet httpget = new HttpGet(url);
// Execute the request
HttpResponse response;
try {
response = httpclient.execute(httpget);
// Examine the response status
Log.i(TAG,response.getStatusLine().toString());
} catch (Exception e) {
Log.i(TAG, e.toString());
}
return null;
}
@Override
protected void onPostExecute(Void results) {
TextView mainTextView = (TextView) findViewById(R.id.main_text_view);
mainTextView.append("\nrequest URL completed");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment