Unirest关于代理设置的文档提及使用:
Unirest.setProxy(new HttpHost(“127.0.0.1”,8000));
由于我使用的代理需要身份验证,我还需要指定凭据,但我不知道如何。
答案 0 :(得分:8)
我解决了它设置自定义客户端而不是代理。
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());