Skip to content

Instantly share code, notes, and snippets.

@omerjerk
Created March 23, 2015 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omerjerk/33c2a16381e7a0523823 to your computer and use it in GitHub Desktop.
Save omerjerk/33c2a16381e7a0523823 to your computer and use it in GitHub Desktop.
Android Http Get example
private class NetworkTask extends AsyncTask<Void, Void, String> {
private String url;
private String parameter;
public NetworkTask(String url, String parameter) {
this.url = url;
this.parameter = parameter;
}
@Override
protected String doInBackground(Void... params) {
HttpClient httpClient = new DefaultHttpClient();
try {
HttpResponse response = httpClient.execute(new HttpGet(
String.format(url, URLEncoder.encode(parameter, "utf-8"))));
String result = EntityUtils.toString(response.getEntity());
return result;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
Log.d("[[Http Result]]", result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment