public static String doPost(Context ctx, String mUrl,
List<NameValuePair> nameValuePairs, String username, String password) {
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 20000;
HttpConnectionParams.setConnectionTimeout(httpParameters,
timeoutConnection);
int timeoutSocket = 20000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);
String response_data = null;
HttpResponse response = null;
if (username != null && password != null) {
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials(username, password));
}
HttpPost postMethod = new HttpPost(mUrl);
try {
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpclient.execute(postMethod);
response_data = EntityUtils.toString(response.getEntity());
} catch (Exception e) {
}
return response_data;
}
}
List<NameValuePair> nameValuePairs, String username, String password) {
HttpParams httpParameters = new BasicHttpParams();
int timeoutConnection = 20000;
HttpConnectionParams.setConnectionTimeout(httpParameters,
timeoutConnection);
int timeoutSocket = 20000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
DefaultHttpClient httpclient = new DefaultHttpClient(httpParameters);
String response_data = null;
HttpResponse response = null;
if (username != null && password != null) {
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
new UsernamePasswordCredentials(username, password));
}
HttpPost postMethod = new HttpPost(mUrl);
try {
postMethod.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpclient.execute(postMethod);
response_data = EntityUtils.toString(response.getEntity());
} catch (Exception e) {
}
return response_data;
}
}
No comments:
Post a Comment