Fiddler 调试 HTTPS Java 应用程序

1、关闭自动抓取,只监听 8888 端口。

点击 Capturing

2、导出根证书文件。

Tool --> Options --> HTTPS --> Actions --> Export Root Certificate to Desktop

3、在 C 盘下创建 keystore 文件夹,将 Fiddler 证书拷贝到 keystore 目录下。

4、创建密钥库文件。

.cer file --> .jks file

cmd 输入命令:keytool -importcert -alias fiddler -file c:\keystore\FiddlerRoot.cer -keystore c:\keystore\fiddler_keystore.jks -storepass abc123456

是否信任此证书:是

说明:

(1)storepass 是密钥,可根据需要设置。

5、设置 https 代理服务器信息。

/**
 * 设置http代理
 * */
public void enableHttpProxy() {
    System.setProperty("https.proxyHost", "127.0.0.1");
    System.setProperty("https.proxyPort", "8888");
}

注意:

(1)https.proxyhost,是 https 不是 http

6、使用 RestTemplate 调用服务。

public class DemoMain {
    public static void main(String[] args) {

        enableHttpProxy(); // set system properties for http proxy

        RestTemplate restTemplate = new RestTemplate();
        String text = restTemplate.getForObject("https://wx.sanguosha.com/api/clock/do", String.class);
        System.out.println(text);
    }


    public static void enableHttpProxy() {
        System.setProperty("https.proxyHost", "127.0.0.1");
        System.setProperty("https.proxyPort", "8888");
    }
}

7、使用密钥库文件。

如果直接运行先前的 DemoMain 类,则在 SSL 握手过程中将抛出异常,由于无法找到验证证书。

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is 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

因此,我们需要使用以下JVM选项运行DemoMain类:

-Djavax.net.ssl.trustStore=c:/keystore/fiddler_keystore.jks -Djavax.net.ssl.trustStorePassword=abc123456

说明:

(1)这两个选项告诉 JVM 在哪里可以找到密钥库文件以及使用密钥库的相应密码。

(2)使用上述选项运行 DemoMain 之后,我们能够从 Fiddler UI 看到 https 请求及其响应。请求和响应都被解码,因此在开发过程中非常有帮助。

8、Fiddler 抓包查看。

一起学习

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

magic_kid_2010

你的支持将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值