【完美解决】用抓包工具抓取idea中使用HttpClient发送的HTTP、HTTPS请求

java代码

HttpGet httpget = new HttpGet(url);
HttpHost proxy = new HttpHost("127.0.0.1",8899);//代理的ip和端口
        RequestConfig requestConfig = RequestConfig.custom()
                .setProxy(proxy)
                .setConnectTimeout(10000)
                .setSocketTimeout(10000)
                .setConnectionRequestTimeout(3000)
                .build();
        httpget.setConfig(requestConfig);

访问https时的问题:unable to find valid certification path to requested target

解决方法:

  1. 找到代理服务器的证书导出cer格式文件
    【完美解决】用抓包工具抓取idea中使用HttpClient发送的HTTP、HTTPS请求_第1张图片

  2. 进入jre/lib/security 目录,执行"/Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/bin/keytool" -import -alias abc -keystore cacerts -file 导出的cer证书路径
    【完美解决】用抓包工具抓取idea中使用HttpClient发送的HTTP、HTTPS请求_第2张图片

  3. 输入口令

    库密钥口令输入:changeit
    是否信任:Y
    证书已添加到密钥库中
    

验证:已经可以抓取到idea中发的请求了【完美解决】用抓包工具抓取idea中使用HttpClient发送的HTTP、HTTPS请求_第3张图片

你可能感兴趣的:(抓包,mac,intellij,idea,java)