我想在可以通过以下java访问的RestAPI上运行负载测试

        name = "username";
        String password = "password";
        String authString = name + ":" + password;
        byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes()); //
        String authStringEnc = new String(authEncBytes);
        URL url = new URL(urlStr);
        URLConnection urlConnection = url.openConnection();
        urlConnection.setRequestProperty("Authorization", "Basic " + authStringEnc);

但是在jmeter中我无法添加此,对jmeter来说是新的,请帮忙。

最佳答案

从JMeter 3.2开始,使用HttpClient4实现提供了基本身份验证,并且默认情况下对其进行了配置,请参见:

  • https://bz.apache.org/bugzilla/show_bug.cgi?id=57242
  • http://jmeter.apache.org/changes.html



  • 只需添加HTTP_Authorization_Manager并填写必填信息。

    例:
  • 对于“http://localhost:8081”的请求:

  • jmeter - 具有基本认证的Jmeter-LMLPHP
  • 配置将为:

  • jmeter - 具有基本认证的Jmeter-LMLPHP

    此配置将匹配以“http://localhost:8081”开头的所有请求

    另请参阅以下问题:
  • JMeter Basic Authentication

  • 尽管我的答案被拒绝,因为我不知道是哪个原因,但这是设置基本身份验证的最佳方法。从3.2开始,根本不再需要脚本。

    09-30 15:30
    查看更多