Created
April 4, 2013 17:04
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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