相关疑难解决方法(0)

如何通过setProperty通过代理使用HttpsURLConnection?

网络环境:

Https客户端<=============>代理服务器<==============> Https Server
                                                  192.168.17.11 <----- extranet --- ---> 192.168.17.22
10.100.21.10 <---- intranet -----> 10.100.21.11

ps:没有默认网关的Http客户端,但它可以ping到10.100.21.11

描述:

操作系统:3台主机上的Ubuntu 12.04
Https客户端:用java实现(openjdk-6).有一个网络接口.
代理服务器:Apache2.2.有两个网络接口.
Https服务器:Tomcat6.Have一个网络接口.

我使用两种方法通过代理实现httpsurlconnection :(
为方便起见我没有写下关于ssl句柄函数来检查serverTrustedhostnameVerifier问题.如果需要我会更新.)

1.Proxy类

InetSocketAddress proxyInet = new InetSocketAddress("10.100.21.11",80);
Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyInet);
URL httpsUrl = new URL("https://192.168.17.22:8443/test");
HttpsURLConnection httpsCon = (HttpsURLConnection) httpsUrl.openConnection(proxy);

httpsCon.setDoOutput(true);
httpsCon.setDoInput(true);
httpsCon.setRequestMethod("POST");
OutputStream out = httpsCon.getOutputStream();
OutputStreamWriter owriter = new OutputStreamWriter(out);

owriter.write("<request>test</request>");
owriter.flush();
owriter.close();
...
Run Code Online (Sandbox Code Playgroud)

这种方法可行,我观察到数据包流量也符合我的期望.
HttpClient ---> ProxyServer ---> HttpServer

但是当我使用set Property方法时:

2.setProperty

System.setProperty("http.proxySet", …
Run Code Online (Sandbox Code Playgroud)

java proxy networking outputstream httpsurlconnection

14
推荐指数
2
解决办法
5万
查看次数