Skip to content

Instantly share code, notes, and snippets.

@pwntester
Created November 5, 2012 11:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pwntester/4016639 to your computer and use it in GitHub Desktop.
Save pwntester/4016639 to your computer and use it in GitHub Desktop.
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