jmeter免证书HTTPS调试

用最通用、全版本兼容的方式跳过SSL校验:(设置完后在测试环境测https接口 就可以不用导入https证书了)

  1. 在你的测试计划上右键,依次点击「添加」→「前置处理器」→「JSR223 前置处理器」。
  2. 语言选择Groovy,直接粘贴这段通用代码,保存后重启JMeter即可生效,所有HTTPS请求都会自动跳过证书校验:

import javax.net.ssl.*;
import java.security.cert.X509Certificate;

TrustManager[] trustAll = new TrustManager[]{
new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() { return null; }
public void checkClientTrusted(X509Certificate[] c, String a) {}
public void checkServerTrusted(X509Certificate[] c, String a) {}
}
};

SSLContext sslCtx = SSLContext.getInstance("TLS");
sslCtx.init(null, trustAll, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sslCtx.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier((h, s) -> true);

posted on 2026-10-28 14:07  FanF  阅读(7)  评论(0)    收藏  举报

导航