Luca S. Luca S. - 1 year ago 245
Java Question

How to set credentials for Unirest proxy?

Documentation for Unirest about proxy settings mentions to use:

Unirest.setProxy(new HttpHost("", 8000));

Since the proxy I'm using requires authentication I would need to specify the credentials too but I don't see how.

Answer Source

I solved it setting a custom client instead of the proxy.

HttpClientBuilder clientBuilder = HttpClientBuilder.create();

  CredentialsProvider credsProvider = new BasicCredentialsProvider();

  credsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(USERNAME, PASSWORD));


  clientBuilder.setProxy(new HttpHost(HOST, PORT));
clientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());

 Lookup<AuthSchemeProvider> authProviders = RegistryBuilder.<AuthSchemeProvider>create()
                    .register(AuthSchemes.BASIC, new BasicSchemeFactory())

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download