0

我正在玩耍并尝试学习 API 如何在 java 中工作,目前正在与 Reddit 搞混:https ://github.com/karan/jReddit

我正在尝试的代码很好用:https ://github.com/karan/jReddit/blob/master/src/main/java/examples/UpvoteExample.java

我想这是进行连接/登录的地方(如果我错了,请纠正我):

User user = new User(restClient, Authentication.getUsername(), Authentication.getPassword());
user.connect();

Submissions subms = new Submissions(restClient, user);
MarkActions submAct = new MarkActions(restClient, user);

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

4

1 回答 1

2

你可以试试这个

        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());
于 2015-05-12T17:22:42.723 回答