网络环境:
Https客户端<=============>代理服务器<==============> Https Server
192.168.17.11 <----- extranet --- ---> 192.168.17.22
10.100.21.10 <---- intranet -----> 10.100.21.11ps:没有默认网关的Http客户端,但它可以ping到10.100.21.11
描述:
操作系统:3台主机上的Ubuntu 12.04
Https客户端:用java实现(openjdk-6).有一个网络接口.
代理服务器:Apache2.2.有两个网络接口.
Https服务器:Tomcat6.Have一个网络接口.
我使用两种方法通过代理实现httpsurlconnection :(
为方便起见我没有写下关于ssl句柄函数来检查serverTrusted和hostnameVerifier问题.如果需要我会更新.)
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方法时:
System.setProperty("http.proxySet", …Run Code Online (Sandbox Code Playgroud)