problem setting proxy credentials in Jakarta HttpClient 2.0

Discussion in 'Java' started by Alex Hunsley, May 26, 2004.

  1. Alex Hunsley

    Alex Hunsley Guest

    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
    Alex Hunsley, May 26, 2004
    #1
    1. Advertising

  2. Alex Hunsley

    Alex Hunsley Guest

    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(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
    Alex Hunsley, May 28, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Richard
    Replies:
    0
    Views:
    664
    Richard
    Apr 26, 2004
  2. Michael Fortin
    Replies:
    1
    Views:
    5,691
    John C. Bollinger
    Oct 12, 2004
  3. Wil Hadden

    Jakarta HttpClient POST question

    Wil Hadden, Nov 8, 2004, in forum: Java
    Replies:
    11
    Views:
    3,685
    blueray
    Jul 1, 2009
  4. Rachel
    Replies:
    0
    Views:
    836
    Rachel
    Oct 17, 2005
  5. Brent

    Jakarta's Latest HttpClient

    Brent, Jan 19, 2006, in forum: Java
    Replies:
    2
    Views:
    5,704
    Brent
    Jan 20, 2006
Loading...

Share This Page