Created
March 23, 2015 19:26
-
-
Save omerjerk/33c2a16381e7a0523823 to your computer and use it in GitHub Desktop.
Android Http Get example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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