Open maloletniy opened 7 years ago
You can use your own HttpTransportClient, with proxy.
.. like that https://github.com/serezhka/vkdump/blob/master/src/main/java/com/github/serezhka/vkdump/config/VkApiConfig.java feel free to use ☺️️
Use extended HttpTransportClient like this (example with http proxy with auth)
public class HttpTransportClientWithProxy extends HttpTransportClient {
public HttpTransportClientWithProxy(Proxy proxy) {
this(3, 3, proxy);
}
public HttpTransportClientWithProxy(int retryAttemptsNetworkErrorCount, int retryAttemptsInvalidStatusCount, Proxy proxy) {
this.retryAttemptsNetworkErrorCount = retryAttemptsNetworkErrorCount;
this.retryAttemptsInvalidStatusCount = retryAttemptsInvalidStatusCount;
CookieStore cookieStore = new BasicCookieStore();
RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(60000).setConnectTimeout(5000).setConnectionRequestTimeout(5000).setCookieSpec("standard").build();
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
connectionManager.setMaxTotal(300);
connectionManager.setDefaultMaxPerRoute(300);
BasicCredentialsProvider proxyAuth = new BasicCredentialsProvider();
proxyAuth.setCredentials(
new AuthScope(proxy.getIp(), proxy.getPort()),
new UsernamePasswordCredentials(proxy.getUser(), proxy.getPassword())
);
httpClient = HttpClients.custom()
.setConnectionManager(connectionManager)
.setDefaultRequestConfig(requestConfig)
.setDefaultCookieStore(cookieStore)
.setDefaultCredentialsProvider(proxyAuth)
.setRoutePlanner(new DefaultProxyRoutePlanner(new HttpHost(proxy.getIp(), proxy.getPort())))
.setUserAgent("Java VK SDK/1.0")
.build();
}
}
Usage
VkApiClient vkClient = new VkApiClient(new HttpTransportClientWithProxy(proxy));
It's not possible to use library over proxy.
The only thing is needed to implement:
RequestConfig requestConfig = RequestConfig.custom()./*blah blah blah*/.setProxy(new HttpHost(hostname, port)).build();
Thanks.