我正在 Eclipse IDE 中运行以下 java 程序:
import java.net.*;
import java.io.*;
public class HH
{
public static void main(String[] args) throws Exception
{
//if i comment out the system properties, and don't set any jvm arguments, the program runs and prints out the html fine.
System.setProperty("http.proxyHost", "localhost");
System.setProperty("http.proxyPort", "8888");
System.setProperty("https.proxyHost", "localhost");
System.setProperty("https.proxyPort", "8888");
URL x = new URL("https://www.google.com");
HttpURLConnection hc = (HttpURLConnection)x.openConnection();
hc.setRequestProperty("User-Agent","Mozilla/5.0 (Windows NT 6.0)
AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2");
InputStream is = hc.getInputStream();
int u = 0;
byte[] kj = new byte[1024];
while((u = is.read(kj)) != -1)
{
System.out.write(kj,0,u);
}
is.close();
}
}
如果 fiddler 正在运行,无论是在捕获还是不捕获时,这都会产生以下异常:
Exception in thread "main" javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown ...
如果我关闭 fiddler,程序运行正常,没有任何异常,在我连接的 url 上生成 html。
或者,如果我指定System.setProperty("https.proxyPort", "443");
, 代替:System.setProperty("https.proxyPort", "8888");
,它运行并打印出所有 html,无一例外,即使 fiddler 打开,处于捕获模式,但仍然没有从 fiddler 捕获。
然后,如果我通过 eclipse 的 jvm 参数设置这些系统属性,例如:-DproxySet=true -DproxyHost=127.0.0.1 -DproxyPort=8888
,只要 fiddler 应用程序在捕获和非捕获模式下运行,同样的异常就会再次发生。如果我关闭 fiddler,程序将运行得很好。
如果我使用:System.setProperty("http.proxyHost", "127.0.0.1");
代替:System.setProperty("http.proxyHost", "localhost");
,它在 fiddler 应用程序运行时运行良好,无论是 cap-/non 捕获模式,但也没有捕获流量。
有没有人能够使用 fiddler 捕获自己的 https 流量,而不是通过网络浏览器,而是通过 java 程序? jvm 参数是什么,如何设置它来执行此操作?谢谢