Thanks for your answer Oleg.
How do I force it to send the user/pass?

About the auth state caching.
I am not sure if I am doing this correctly, please correct me if I am wrong.

var credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope("127.0.0.1", 8080),
        new UsernamePasswordCredentials("foo", "bar"));

//Create the target and proxy hosts
HttpHost targetHost = new HttpHost("https://www.google.com";, 443, "https");
HttpHost proxyHost = new HttpHost("127.0.0.1", 8080, "http");

var httpclient = HttpClients.custom()
        .setProxy(proxyHost)
        .setProxyAuthenticationStrategy(?? )
        .build();

var authCache = new BasicAuthCache();
var basicAuth = new BasicScheme();
authCache.put(proxyHost, basicAuth);

var localContext = HttpClientContext.create();
localContext.setAuthCache(authCache);
localContext.setCredentialsProvider(credsProvider);

//Setting the proxy
var config = RequestConfig.custom().setProxy(proxyHost).build();

//Create the HttpGet request object
var httpGet = new HttpGet("/");

//Setting the config to the request
httpGet.setConfig(config);

//Printing the status line
var response = httpclient.execute(targetHost, httpGet, localContext);

var result = response.getStatusLine();




On Thu, 17 Feb 2022 at 19:11, Oleg Kalnichevski <ol...@apache.org> wrote:

> On Thu, 2022-02-17 at 15:21 +0000, Jhonny Knaak de Vargas wrote:
> > Just sending this email again because I was not subscribed the first
> > time I sent.
> > Not sure if this has any kind of impact.
> >
> > > Begin forwarded message:
> > >
> > > From: Jhonny Knaak de Vargas <jho...@evervault.com>
> > > Subject: Proxy authorization not being sent.
> > > Date: 17 February 2022 at 15:13:53 GMT
> > > To: httpclient-users@hc.apache.org
> > >
> > > I was not able to send the proxy user and password to the proxy
> > > using the code at the bottom of this email.
> > > I got some questions,
> > >
> > > Does the library send a first connection without a user/pass
> > > attempting to get back a PROXY-AUTHENTICATE BASIC for example?
> > >
>
> HttpClient does not use preemptive authentication by default (which is
> by design). It have got to force it to do.
>
> It is however recommended to use auth state caching instead.
>
>
> > > Is there any difference between setting the proxy at the HttpClient
> > > level from the one available at the RequestConfig?
> > >
>
> No, there is not.
>
> Oleg
>
> > > Thanks.
> > > Jhonny
> > >
> > >
> > > code used:
> > >
> > > var credsProvider = new BasicCredentialsProvider();
> > >
> > > credsProvider.setCredentials(new AuthScope("localhost", 8080),
> > >         new UsernamePasswordCredentials("someUser", "somePass"));
> > >
> > > var proxyHost = new HttpHost("localhost", 8080, "http");
> > >
> > > var httpclient =
> > > HttpClients.custom().setDefaultCredentialsProvider(credsProvider)
> > >         .setSSLContext(new
> > > SSLContextBuilder().loadTrustMaterial(null,
> > > TrustAllStrategy.INSTANCE).build())
> > >         .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
> > >         //.setProxy(proxyHost)
> > >         .build();
> > >
> > > //Create the target and proxy hosts
> > > var targetHost = new HttpHost("enssc1aqsjv0g.x.pipedream.net <
> > > http://enssc1aqsjv0g.x.pipedream.net/>;", 443, "https");
> > >
> > > //Setting the proxy
> > > var config = RequestConfig.custom().setProxy(proxyHost).build();
> > >
> > > //Create the HttpGet request object
> > > var httpget = new HttpGet("/");
> > >
> > > //Setting the config to the request
> > > httpget.setConfig(config);
> > >
> > > //Printing the status line
> > > var response = httpclient.execute(targetHost, httpget);
> > >
> > > var result = response.getStatusLine();
> > >
> > > assertNotNull(result);
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
> For additional commands, e-mail: httpclient-users-h...@hc.apache.org
>
>

Reply via email to