Hi,
I'm trying to make a GET request through a HTTP proxy (squid) with basic
authentication (user and password).
I found a sample of how to do that using version 3.0, but for version 4.x I
can't found this.
I'm using the code below, but it isn't working.
HttpRequestBase httpmethod = null;
HttpResponse response = null;
DefaultHttpClient httpclient = null;
HttpHost proxy = null;
StringBuilder resultText = new StringBuilder("");
httpclient = new DefaultHttpClient();
proxy = new HttpHost(proxyHost, proxyPort);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
proxy);
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(proxyHost,
proxyPort),
new
UsernamePasswordCredentials(proxyUserName, proxyPassword));
httpmethod = new HttpGet(url);
response = httpclient.execute(httpmethod);
Below an extract from the log:
2011/01/24 00:13:47:054 GMT [DEBUG] DefaultHttpClient - Proxy requested
authentication
2011/01/24 00:13:47:054 GMT [DEBUG] DefaultProxyAuthenticationHandler -
Authentication schemes in the order of preference: [negotiate, NTLM, Digest,
Basic]
2011/01/24 00:13:47:054 GMT [DEBUG] DefaultProxyAuthenticationHandler -
Challenge for negotiate authentication scheme not available
2011/01/24 00:13:47:055 GMT [DEBUG] DefaultProxyAuthenticationHandler -
Challenge for NTLM authentication scheme not available
2011/01/24 00:13:47:055 GMT [DEBUG] DefaultProxyAuthenticationHandler -
Challenge for Digest authentication scheme not available
2011/01/24 00:13:47:055 GMT [DEBUG] DefaultProxyAuthenticationHandler -
Basic authentication scheme selected
2011/01/24 00:13:47:064 GMT [DEBUG] DefaultHttpClient - Authorization
challenge processed
2011/01/24 00:13:47:065 GMT [DEBUG] DefaultHttpClient - Authentication
scope: BASIC '*Enter user and password*'@192.168.160.3:8080
2011/01/24 00:13:47:065 GMT [DEBUG] DefaultHttpClient - Found credentials
2011/01/24 00:13:47:066 GMT [DEBUG] DefaultClientConnection - Connection
closed
2011/01/24 00:13:47:066 GMT [DEBUG] DefaultClientConnectionOperator -
Connecting to /192.168.160.3:8080
2011/01/24 00:13:47:741 GMT [DEBUG] RequestAddCookies - CookieSpec selected:
best-match
2011/01/24 00:13:47:747 GMT [DEBUG] DefaultClientConnection - Connection
shut down
Anyone could help?
Thanks,
Rodrigo B. Campacci
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]