为 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的更多相关文章

  1. Jersey(1.19.1) - Client API, Overview of the API

    To utilize the client API it is first necessary to create an instance of a Client, for example: Clie ...

  2. Jersey(1.19.1) - Client API, Uniform Interface Constraint

    The Jersey client API is a high-level Java based API for interoperating with RESTful Web services. I ...

  3. Jersey(1.19.1) - Client API, Ease of use and reusing JAX-RS artifacts

    Since a resource is represented as a Java type it makes it easy to configure, pass around and inject ...

  4. Jersey(1.19.1) - Client API, Using filters

    Filtering requests and responses can provide useful functionality that is hidden from the applicatio ...

  5. Jersey(1.19.1) - Client API, Testing services

    The Jersey client API was originally developed to aid the testing of the Jersey server-side, primari ...

  6. Jersey(1.19.1) - Client API, Security with Http(s)URLConnection

    With Http(s)URLConnection The support for security, specifically HTTP authentication and/or cookie m ...

  7. docker报Error response from daemon: client is newer than server (client API version: 1.24, server API version: 1.19)

    docker version Client: Version: 17.05.0-ce API version: 1.24 (downgraded from 1.29) Go version: go1. ...

  8. Jersey(1.19.1) - JSON Support

    Jersey JSON support comes as a set of JAX-RS MessageBodyReader<T> and MessageBodyWriter<T&g ...

  9. Java 9 揭秘(14. HTTP/2 Client API)

    Tips 做一个终身学习的人. 在此章中,主要介绍以下内容: 什么是HTTP/2 Client API 如何创建HTTP客户端 如何使HTTP请求 如何接收HTTP响应 如何创建WebSocket的e ...

随机推荐

  1. POJ1179Polygon(DP)

    Polygon Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4456   Accepted: 1856 Descripti ...

  2. Http通讯协议在.net下的实现方法

    1.HttpwebRequest and  HttpWebResponse 2.客户端访问服务端的API:HttpClient 3. .net下的Remoting 4.Web Services 5.W ...

  3. weak nonatomic strong等介绍(ios)

    @property的属性weak nonatomic strong等介绍(ios) 2014-12-02 18:06 676人阅读 评论(0) 收藏 举报 学习ios也已经快半个月了,也尝试做简单的应 ...

  4. 用6个字符写出任意的Javascript代码

    博客搬到了fresky.github.io - Dawei XU,请各位看官挪步.最新的一篇是:用6个字符写出任意的Javascript代码.

  5. VC中监测函数运行时间(一)—分钟,秒,毫秒

    //myTimer.h // [10/16/2013 Duan Yihao] #pragma once #include "StdAfx.h" ////////////////// ...

  6. <select>改造成<s:select>实现表单的回显功能

    初始: <select name="viewType"> <option value="0">全部主题</option> & ...

  7. linux常用命令-搜索

    1.find $ find . -name nginx* $ find . -name nginx* -ls $ find . -type f -mmin -10 搜索当前目录中,所有过去10分钟中更 ...

  8. 测试URL有效性

    方法一: #禁用滚动条 $ProgressPreference='silentlycontinue' Invoke-WebRequest "www.163.com" -UseBas ...

  9. sql 指令

    SELECT 是用来做什么的呢?一个最经常使用的方式是将资料从数据库中的表格内选出.从这一句回答中.我们立即能够看到两个keyword:从 (FROM)数据库中的表格内选出 (SELECT).(表格是 ...

  10. LINUX 文件系统如何存储文件 图解

    http://zhuqiuxu.iteye.com/blog/2116023 http://zhuqiuxu.iteye.com/blog/2116168 理解Inode要从文件说起,文件存储在硬盘上 ...