HttpClient httpclient = new DefaultHttpClient();
String responseBody = null;
try
{
HttpGet httpGet = new HttpGet(url);
HttpConnectionParams.setConnectionTimeout(httpGet.getParams(), timeout * 1000);
HttpConnectionParams.setSoTimeout(httpGet.getParams(), timeout * 1000);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
responseBody = httpclient.execute(httpGet, responseHandler);
}
finally
{
httpclient.getConnectionManager().shutdown();
}
return responseBody;
HttpClient httpclient = new DefaultHttpClient();
ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
String responseBody = null;
try
{
String[] nameAndValues = body.split("&");
for (String nameAndValue : nameAndValues)
{
String[] nameValue = nameAndValue.split("=");
params.add(new BasicNameValuePair(nameValue[0], nameValue[1]));
}
HttpPost httpPost = new HttpPost(url);
HttpConnectionParams.setConnectionTimeout(httpPost.getParams(), timeout * 1000);
HttpConnectionParams.setSoTimeout(httpPost.getParams(), timeout * 1000);
httpPost.setEntity(new UrlEncodedFormEntity(params));
ResponseHandler<String> responseHandler = new BasicResponseHandler();
responseBody = httpclient.execute(httpPost, responseHandler);
}
finally
{
httpclient.getConnectionManager().shutdown();
}
return responseBody;