【问题标题】:Perform HTTPS-Request using Preprocessor in JMeter在 JMeter 中使用预处理器执行 HTTPS 请求
【发布时间】:2021-03-10 13:49:05
【问题描述】:

我有 HTTPS GET 请求要在我的实际 HTTP 采样器之前使用预处理器执行

有没有办法使用预处理器访问 api(https) ?

【问题讨论】:

    标签: javascript groovy jmeter beanshell jmeter-4.0


    【解决方案1】:

    您可以使用JSR223 PreProccessor,只需使用您的网站创建一个 URL:

    new URL("https://www.google.com").openConnection()
    

    【讨论】:

    • 我收到以下错误 1. 'javax.script.ScriptException: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath .SunCertPathBuilderException: 无法找到请求目标的有效证书路径'
    【解决方案2】:

    类似:

    import javax.net.ssl.HttpsURLConnection
    import javax.net.ssl.X509TrustManager
    
    class TrustManager implements X509TrustManager {
        public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null;  }
        public void checkClientTrusted(java.security.cert.X509Certificate[] certs, String authType) { }
        public void checkServerTrusted(java.security.cert.X509Certificate[] certs, String authType) { }
    }
    def context = javax.net.ssl.SSLContext.getInstance('SSL') // or maybe `TLS` depending on your endpoint configuration
    context.init(null, (TrustManager[]) [new TrustManager()], new java.security.SecureRandom())
    HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory())
    
    log.info('https://your URL here /'.toURL().text)
    

    应该为您解决问题。

    最后一行将打印端点响应jmeter.log file

    更多信息:

    【讨论】:

    • 它对 GET 请求运行良好,但面临 POST 请求的问题。传递 POST 请求有什么建议吗?
    • 它对 GET 请求运行良好,但面临 POST 请求的问题。传递 POST 请求有什么建议吗?方法 : POST Payload/Request : {"data": { "Environment": "CI", "Host": "abc.com" }} Headers: Content-Type: application/json Endpoint/URL : example.com跨度>
    猜你喜欢
    • 2022-07-15
    • 1970-01-01
    • 1970-01-01
    • 2015-06-05
    • 2020-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多