2015-04-03 90 views
0

我玩弄和努力学习API在Java中是如何工作的,目前乱搞与reddit的一个:那我想出来https://github.com/karan/jRedditHttpRestClient()通过代理?

守则,工作得很好: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); 

是否可以通过代理在上面的代码连接?

回答

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());