Documentation for Unirest about proxy settings mentions to use:
Unirest.setProxy(new HttpHost("127.0.0.1", 8000));
Since the proxy I'm using requires authentication I would need to specify the credentials too but I don't see how.
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.useSystemProperties();
clientBuilder.setProxy(new HttpHost(HOST, PORT));
clientBuilder.setDefaultCredentialsProvider(credsProvider);
clientBuilder.setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy());
Lookup<AuthSchemeProvider> authProviders = RegistryBuilder.<AuthSchemeProvider>create()
.register(AuthSchemes.BASIC, new BasicSchemeFactory())
.build();
clientBuilder.setDefaultAuthSchemeRegistry(authProviders);
Unirest.setClient(clientBuilder.build());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With