Java HttpRestClient()是否通过代理?

Java HttpRestClient()是否通过代理?,java,jreddit,Java,Jreddit,我正在四处玩,试图了解API在java中的工作原理,目前正在与Reddit one混为一谈: 我正在尝试的代码,效果很好: 我猜这就是建立连接/登录的地方(如果我错了,请纠正我): 是否可以通过上面代码中的代理进行连接?您可以试试这个 final RequestConfig globalConfig = RequestConfig.custom() .setCookieSpec(CookieSpecs.IGNORE_COOKIES)

我正在四处玩,试图了解API在java中的工作原理,目前正在与Reddit one混为一谈:

我正在尝试的代码,效果很好:

我猜这就是建立连接/登录的地方(如果我错了,请纠正我):

是否可以通过上面代码中的代理进行连接?

您可以试试这个

        final RequestConfig globalConfig = RequestConfig.custom()
                .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
                .setConnectionRequestTimeout(10000).build();
        HttpHost proxy = new HttpHost("YOUR_PROXY_IP", YOUR_PROXY_PORT);
        final HttpClient httpClient = HttpClients.custom()
                .setProxy(proxy)
                .setDefaultRequestConfig(globalConfig).build();
        final ResponseHandler<Response> responseHandler = new RestResponseHandler();
        final RestClient restClient = new HttpRestClient(httpClient, responseHandler);
        restClient.setUserAgent("bot/1.0 by name");

        // Connect the user 
        User user = new User(restClient, Authentication.getUsername(), Authentication.getPassword());
final RequestConfig globalConfig=RequestConfig.custom()
.setCookieSpec(CookieSpecs.IGNORE_COOKIES)
.setConnectionRequestTimeout(10000).build();
HttpHost proxy=新的HttpHost(“您的代理IP”,即您的代理端口);
最终HttpClient-HttpClient=HttpClients.custom()
.setProxy(代理)
.setDefaultRequestConfig(globalConfig.build();
最终响应Handler ResponseHandler=新ResponseHandler();
最终RestClient RestClient=新的HttpRestClient(httpClient,responseHandler);
setUserAgent(“bot/1.0按名称”);
//连接用户
User User=新用户(restClient,Authentication.getUsername(),Authentication.getPassword());
        final RequestConfig globalConfig = RequestConfig.custom()
                .setCookieSpec(CookieSpecs.IGNORE_COOKIES)
                .setConnectionRequestTimeout(10000).build();
        HttpHost proxy = new HttpHost("YOUR_PROXY_IP", YOUR_PROXY_PORT);
        final HttpClient httpClient = HttpClients.custom()
                .setProxy(proxy)
                .setDefaultRequestConfig(globalConfig).build();
        final ResponseHandler<Response> responseHandler = new RestResponseHandler();
        final RestClient restClient = new HttpRestClient(httpClient, responseHandler);
        restClient.setUserAgent("bot/1.0 by name");

        // Connect the user 
        User user = new User(restClient, Authentication.getUsername(), Authentication.getPassword());