首页 > Windows开发 > 详细

Jersey(1.19.1) - Client API, Proxy Configuration

时间:2016-07-31 01:39:36      阅读:287      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!