Proxy Example
##Proxy Example SometimesSometimes you need to use a Proxy to access the internet. At my company we need to. StackWrap4J provides the ability to specify a Proxy server to rout connections through.
Below is a short code sample that configures the proxy, and then pulls every answer that I (2598) have given.
Proxy prox = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
"proxy.my.company.com", 80));
HttpClient.proxyServer = prox;
StackWrapper sw = new StackOverflow();
AnswerQuery query = new AnswerQuery();
query.setPageSize(PageQuery.MAX_PAGE_SIZE).setIds(2598);
List<Answer> allAnswers = new AnswerFromUserList(sw, query);
It is as simple as setting the public proxyServer
property of the HttpClient
class. That proxy will be used continually unless you set proxyServer
to null
.