problem setting proxy credentials in Jakarta HttpClient 2.0

A

Alex Hunsley

Anyone else had problems with setting the proxy credentials (i.e. username,
password) in Jakarta HttpClient 2.0?

Sorry, no complete code I could post at this time, but the important part looks
like this:



HttpClient httpClient = new HttpClient();

httpClient.getHostConfiguration().setProxy(proxyAddress, proxyPort);

httpState.setProxyCredentials(null, // realm - null is default
null, // proxy host
new UsernamePasswordCredentials("usernameHere", "passwordHere"));

[[... then use HttpClient to access a web page using Post method]]


The second line, i.e. the setting of the proxy host and port, works. My test
proxy server (using Charles: http://www.xk72.com/charles/) does get used.
Howver, the last line, where I set the proxy credentials, has no effect - the
credentials don't get supplied to the proxy. AFAICT from the docs on
HttpClient, a null realm and null proxy host are the right way to specify the
default proxy credentials, can anyone comment on this?

(Btw, I've tested my proxy server (Charles) by using wget, and when I set proxy
credentials when using wget, they do show up in Charles, so it's not a case of
my proxy server just not telling me when credentials have been supplied!)

I am going mad here so any help appreciated!
thanks
alex
 
A

Alex Hunsley

Alex said:
Anyone else had problems with setting the proxy credentials (i.e.
username, password) in Jakarta HttpClient 2.0?

Sorry, no complete code I could post at this time, but the important
part looks like this:



HttpClient httpClient = new HttpClient();

httpClient.getHostConfiguration().setProxy(proxyAddress,
proxyPort);

httpState.setProxyCredentials(null, // realm - null is default
null, // proxy host
new UsernamePasswordCredentials("usernameHere", "passwordHere"));

[[... then use HttpClient to access a web page using Post method]]


The second line, i.e. the setting of the proxy host and port, works. My
test proxy server (using Charles: http://www.xk72.com/charles/) does get
used.
Howver, the last line, where I set the proxy credentials, has no effect
- the credentials don't get supplied to the proxy. AFAICT from the docs
on HttpClient, a null realm and null proxy host are the right way to
specify the default proxy credentials, can anyone comment on this?

(Btw, I've tested my proxy server (Charles) by using wget, and when I
set proxy credentials when using wget, they do show up in Charles, so
it's not a case of my proxy server just not telling me when credentials
have been supplied!)

I am going mad here so any help appreciated!
thanks
alex

Replying to myself for potential benefit to others...

Solved it. The answer is that the default behaviour of HttpClient is, for some
reason, to just bail out if it requests a web page and then gets a 407
"authentication required" code (even if you have set the authentication
details). Howver, if you call:

httpMethod = ... [some HttpMethod subclass]
httpMethod.setDoAuthentication(true)

then HttpClient will reply to the 407 code with the authentication details in a
transparent fashion and all is happy and it works.

alex
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top