泽西岛2.0通过代理获得电话

lea*_*ner 7 java rest jersey-2.0

我正在使用Jersey 2.4.1进行休息,并希望通过HTTP和HTTPS代理进行GET或Post调用.我无法做到.我已经在互联网上搜索并找到了许多链接,但现在大部分已经过时了.一些帮助将非常有用,因为从Jersey 1.X到2.X有很多变化

这是我的GET调用代码(工作正常).我想修改它以通过HTTP和HTTPS代理进行此调用.任何指针都会有所帮助.

javax.ws.rs.core.Response response = null;
Client client = ClientBuilder.newClient();
WebTarget target = client.target(url); //url is string
response = target.request().header("Authorization", header).accept(javax.ws.rs.core.MediaType.APPLICATION_JSON).get();
Run Code Online (Sandbox Code Playgroud)

Dis*_*ubo 1

尝试使用 ClientConfiguration 对象,设置所需的任何属性,然后使用 ClientBuilder.withConfig(Configuration config) 设置配置。然后你可以使用 build() 方法构建它。看看这个例子:

ClientConfig cc = new ClientConfig();
cc.property(ClientProperties.PROXY_URI, "8.8.8.8:80");
Client client = JerseyClientBuilder.withConfig(cc).build();
Run Code Online (Sandbox Code Playgroud)

然而,这仅适用于 http 代理。要设置 https 代理,您必须设置系统属性,如下所示:

System.setProperty("http.proxyHost", "some.proxy");
System.setProperty("http.proxyPort", "3476");
System.setProperty("https.proxyHost", "some.https.proxy");
System.setProperty("https.proxyPort", "6235");
Run Code Online (Sandbox Code Playgroud)

阅读本文以获取更多信息。