我正在玩游戏并试图了解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);
是否可以通过上面代码中的代理连接?
答案 0 :(得分: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());