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 paul_b <pb...@gmail.com> on 2012/07/04 10:29:54 UTC
Need an example of user authentication for BOTH proxy and target???
Hi,
I have been looking on the internet and unable to find an example of the
DefaultHttpClient class with the capability of using user authentication for
both proxy and target. I can see from the document that there are examples
of user authentication for either proxy and target, both not both! I can
see examples of older libraries with this scenario, but not the latest. I
would much appreciate if someone could post an example.
Cheers,
paul
--
View this message in context: http://old.nabble.com/Need-an-example-of-user-authentication-for-BOTH-proxy-and-target----tp34111923p34111923.html
Sent from the HttpClient-User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Need an example of user authentication for BOTH proxy and
target???
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2012-07-04 at 02:38 -0700, paul_b wrote:
> Thanks for your reply. Looking at my code, which I think there is nothing
> different than the examples, I cant see how... I have included a snippet of
> my code below. I was expecting something in the ConnRoutePNames according
> to what you say but there doesnt seem to be.
>
> httpclient.getCredentialsProvider().setCredentials(
> new AuthScope(PROXY_URL, PROXY_PORT),
> new UsernamePasswordCredentials(credentials.getUsername(),
> credentials.getPassword()));
> HttpHost proxy = new HttpHost(PROXY_URL, PROXY_PORT);
> httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
> proxy);
>
>
Careful with the PROXY_URL variable. It must contain a hostname (such as
locahost), not a URL (such as http://localhost/).
All you have to do is to add credentials for the target host:
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(PROXY_HOST, PROXY_PORT),
new UsernamePasswordCredentials("user:password");
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(TARGET_HOST, TARGET_PORT),
new UsernamePasswordCredentials("user:password");
HttpHost proxy = new HttpHost(PROXY_HOST, PROXY_PORT);
httpclient.getParams().setParameter(
ConnRoutePNames.DEFAULT_PROXY, proxy);
Oleg
>
> olegk wrote:
> >
> > On Wed, 2012-07-04 at 01:29 -0700, paul_b wrote:
> >> Hi,
> >> I have been looking on the internet and unable to find an example of
> >> the
> >> DefaultHttpClient class with the capability of using user authentication
> >> for
> >> both proxy and target. I can see from the document that there are
> >> examples
> >> of user authentication for either proxy and target, both not both! I can
> >> see examples of older libraries with this scenario, but not the latest.
> >> I
> >> would much appreciate if someone could post an example.
> >>
> >> Cheers,
> >> paul
> >
> > There is nothing special about it. Just make sure you provide
> > credentials for both target and proxy hosts. HttpClient will do the rest
> > automatically.
> >
> > Oleg
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> > For additional commands, e-mail: httpclient-users-help@hc.apache.org
> >
> >
> >
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Need an example of user authentication for BOTH proxy and
target???
Posted by paul_b <pb...@gmail.com>.
Thanks for your reply. Looking at my code, which I think there is nothing
different than the examples, I cant see how... I have included a snippet of
my code below. I was expecting something in the ConnRoutePNames according
to what you say but there doesnt seem to be.
httpclient.getCredentialsProvider().setCredentials(
new AuthScope(PROXY_URL, PROXY_PORT),
new UsernamePasswordCredentials(credentials.getUsername(),
credentials.getPassword()));
HttpHost proxy = new HttpHost(PROXY_URL, PROXY_PORT);
httpclient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY,
proxy);
olegk wrote:
>
> On Wed, 2012-07-04 at 01:29 -0700, paul_b wrote:
>> Hi,
>> I have been looking on the internet and unable to find an example of
>> the
>> DefaultHttpClient class with the capability of using user authentication
>> for
>> both proxy and target. I can see from the document that there are
>> examples
>> of user authentication for either proxy and target, both not both! I can
>> see examples of older libraries with this scenario, but not the latest.
>> I
>> would much appreciate if someone could post an example.
>>
>> Cheers,
>> paul
>
> There is nothing special about it. Just make sure you provide
> credentials for both target and proxy hosts. HttpClient will do the rest
> automatically.
>
> Oleg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>
>
--
View this message in context: http://old.nabble.com/Need-an-example-of-user-authentication-for-BOTH-proxy-and-target----tp34111923p34112192.html
Sent from the HttpClient-User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Need an example of user authentication for BOTH proxy and
target???
Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2012-07-04 at 01:29 -0700, paul_b wrote:
> Hi,
> I have been looking on the internet and unable to find an example of the
> DefaultHttpClient class with the capability of using user authentication for
> both proxy and target. I can see from the document that there are examples
> of user authentication for either proxy and target, both not both! I can
> see examples of older libraries with this scenario, but not the latest. I
> would much appreciate if someone could post an example.
>
> Cheers,
> paul
There is nothing special about it. Just make sure you provide
credentials for both target and proxy hosts. HttpClient will do the rest
automatically.
Oleg
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org