DownloadWebPageTask task = new DownloadWebPageTask(); task.execute("http://yahoo.com","param1","value1");
private class DownloadWebPageTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
// url, param1Name, param1Value,...
if(urls.length < 3) return null;
String url = urls[0];
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair(urls[1], urls[2]));
String resString = null;
try{
post.setEntity(new UrlEncodedFormEntity(pairs));
HttpResponse res = client.execute(post);
HttpEntity entity = res.getEntity();
resString = EntityUtils.toString(entity);
}catch(Exception e){
Log.e(null, e.toString());
}
return resString;
}
@Override
protected void onPostExecute(String result) {
//do something
}
}
ref : http://www.wikihow.com/Execute-HTTP-POST-Requests-in-Android
댓글
댓글 쓰기