Skip to content

Instantly share code, notes, and snippets.

@jnwelzel
Created April 4, 2013 17:04
Show Gist options
  • Save jnwelzel/5312133 to your computer and use it in GitHub Desktop.
Save jnwelzel/5312133 to your computer and use it in GitHub Desktop.
The boilerplate needed to make a http request behind a proxy that requires authentication
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 5000);
HttpConnectionParams.setSoTimeout(httpParams, 5000);
DefaultHttpClient client = new DefaultHttpClient(httpParams);
client.getCredentialsProvider().setCredentials(
new AuthScope(PROXY_HOSTNAME, PROXY_PORT),
new UsernamePasswordCredentials(PROXY_USERNAME, PROXY_USERPWD));
HttpHost proxy = new HttpHost(PROXY_HOSTNAME, PROXY_PORT);
client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
HttpGet get = new HttpGet(HTTP_URL);
HttpResponse response = client.execute(get);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment