Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
executeRequest
private void executeRequest(HttpUriRequest request, String url,
Context context) {
HttpClient client = CustomSSLSocketFactory.getNewHttpClient();
HashMap<String, String> proxyInfo = Utils.getProxyMap(context);
String proxyHost = proxyInfo.get("proxyHost");
String proxyPort = proxyInfo.get("proxyPort");
if (!(proxyHost.equals("") || proxyPort.equals(""))) {
HttpHost proxy = new HttpHost(proxyHost,
Integer.parseInt(proxyPort));
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
proxy);
}
HttpResponse httpResponse;
try {
httpResponse = client.execute(request);
responseCode = httpResponse.getStatusLine().getStatusCode();
message = httpResponse.getStatusLine().getReasonPhrase();
HttpEntity entity = httpResponse.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
response = convertStreamToString(instream);
// Closing the input stream will trigger connection release
instream.close();
}
} catch (ClientProtocolException e) {
client.getConnectionManager().shutdown();
} catch (IOException e) {
client.getConnectionManager().shutdown();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment