You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by raef kandeel <ra...@gmail.com> on 2008/02/20 11:36:12 UTC

Re: I have a problem with HttpClient

On Feb 20, 2008 12:29 PM, raef kandeel <ra...@gmail.com> wrote:

> Dears, please have look at the following code:-
>
> *
>
> import
> *org.apache.commons.httpclient.auth.AuthPolicy;*
>
> import
> *org.apache.commons.httpclient.auth.AuthScope;*
>
> import
> *org.apache.commons.httpclient.methods.GetMethod;*
>
> import
> *org.apache.commons.httpclient.HttpMethod;
>
> *
>
> public
> **class* HttpClientTest {
>
> *private* *void* execute() *throws* HttpException, IOException {
>
> HttpClient proxyclient =
> *new* HttpClient();
>
> proxyclient.getHostConfiguration().setHost(
> www.someaddress.com);
>
> proxyclient.getHostConfiguration().setProxy(
> "somproxy.proxy.whatever", 8080);
>
> HttpMethod method =
> *new* GetMethod("http://www.google.com");
>
> method.setFollowRedirects(
> *true*);
>
> proxyclient.executeMethod(method);
>
> List authPrefs =
> *new* ArrayList();
>
> authPrefs.add(AuthPolicy.
> *NTLM*);
>
> proxyclient.getState().setProxyCredentials(
>
> *new* AuthScope("http://www.google.com", 8080),
>
> *new* NTCredentials("username\\company", "password", "", "proxy.whatever"));//note
> the username\company is the username. Although is is not the same username,
> it has the same structure.
>
> proxyclient.getParams().setParameter(AuthPolicy.
> *AUTH_SCHEME_PRIORITY*, authPrefs);
>
>   System.*out*.println("Content length: " + method.getResponseBodyAsString().length());
>
>
>  System.
> *out*.println (method.getResponseBodyAsString());
>
> }
>
>
>
> *public* *static* *void* main(String[] args) *throws* HttpException,
> IOException {
>
> *new* HttpClientTest().execute();
>
> }
>
> }
>
>
>
> And it gives me the following:-
>
>
>
> 20-Feb-2008 12:07:44
> org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme
>
> INFO: ntlm authentication scheme selected
>
> 20-Feb-2008 12:07:44 org.apache.commons.httpclient.HttpMethodDirectorprocessProxyAuthChallenge
>
> INFO: No credentials available for NTLM <any realm>@
> somproxy.proxy.whatever:8080
>
> And then it gives me the proxy error page.
>
> Help me out please....
>



-- 
Thanks and Best Regards

Websphere Specialist Raef Kandeel
Production Support
Professional Services Department

Phone        : +966 (01) 4549322
Fax        :    +966 (01)4549322
Mobile        : +966 566921065
Email        : raefkandeel2008@gmail.com