码迷,mamicode.com
首页 > Windows程序 > 详细

Jersey(1.19.1) - Client API, Proxy Configuration

时间:2016-07-31 01:41:56      阅读:256      评论:0      收藏:0      [点我收藏+]

标签:

 为 Jersey Client 设置代理,可以使用带有 ClientHandler 参数的构造方法创建 Client 实例。

public static void main(String[] args) {
    final Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8080));
    Client client = new Client(new URLConnectionClientHandler(new HttpURLConnectionFactory() {            
        public HttpURLConnection getHttpURLConnection(URL url) throws IOException {
            return (HttpURLConnection) url.openConnection(proxy);
        }
    }));

    WebResource resource = client.resource("http://example.com");
    ClientResponse response = resource.get(ClientResponse.class);
    System.out.println(String.format("%s %s", 
            response.getStatusInfo().getStatusCode(), 
            response.getStatusInfo().getReasonPhrase()));
}

 

Jersey(1.19.1) - Client API, Proxy Configuration

标签:

原文地址:http://www.cnblogs.com/huey/p/5721923.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!