Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > problem setting proxy credentials in Jakarta HttpClient 2.0

Reply
Thread Tools

problem setting proxy credentials in Jakarta HttpClient 2.0

 
 
Alex Hunsley
Guest
Posts: n/a
 
      05-26-2004
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(proxyAd dress, 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

 
Reply With Quote
 
 
 
 
Alex Hunsley
Guest
Posts: n/a
 
      05-28-2004
Alex Hunsley wrote:

> 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(proxyAd dress,
> 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





 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Jakarta HttpClient POST question Wil Hadden Java 11 07-01-2009 05:21 PM
Jakarta's Latest HttpClient Brent Java 2 01-20-2006 05:36 AM
Using Jakarta HTTPClient StrictSSLProtocolSocketFactory with proxy Rachel Java 0 10-17-2005 11:37 AM
Keeping session alive using jakarta httpclient Michael Fortin Java 1 10-12-2004 02:13 PM
Help with Jakarta HttpClient Cookies Richard Java 0 04-26-2004 09:14 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57