Смотрите этот пример кода.Это поможет вам.
HttpContext localContext = new BasicHttpContext();
String ret = null;
HttpClient httpClient = new DefaultHttpClient();
httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY,
CookiePolicy.RFC_2109);
HttpPost httpPost = new HttpPost(url);
HttpResponse response = null;
StringEntity tmp = null;
httpPost.setHeader(
"Accept",
"text/html,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
try {
tmp = new StringEntity(data, "UTF-8");
} catch (UnsupportedEncodingException e) {
Log.e("Your App Name Here",
"HttpUtils : UnsupportedEncodingException : " + e);
}
httpPost.setEntity(tmp);
try {
response = httpClient.execute(httpPost, localContext);
if (response != null) {
ret = EntityUtils.toString(response.getEntity());
Log.i("result", ret);
}
} catch (Exception e) {
Log.e("Your App Name Here", "HttpUtils: " + e);
}