Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
具有基本身份验证的Jmeter_Jmeter_Jmeter Plugins - Fatal编程技术网

具有基本身份验证的Jmeter

具有基本身份验证的Jmeter,jmeter,jmeter-plugins,Jmeter,Jmeter Plugins,我想在RestAPI上运行loadtest,我可以通过下面的java访问它 name = "username"; String password = "password"; String authString = name + ":" + password; byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes()); // Stri

我想在RestAPI上运行loadtest,我可以通过下面的java访问它

        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实现提供的,并在默认情况下进行配置,请参阅:

HTTP HC4实现现在提供了默认启用的抢占式基本身份验证

只需添加并填写所需信息

例如:

  • 要将此请求发送到“”:

  • 配置将是:

此配置将匹配以“”开头的任何请求

另见这个问题:


虽然我的答案被否决了,但我不知道是什么原因,这是设置基本身份验证的最佳方式。自3.2版以来,不再需要编写脚本。

您可以使用相同的代码生成编码凭据:

  • 添加为相关HTTP请求采样器的子级
  • 添加为相关HTTP请求采样器的子级
  • 将以下代码放入“脚本”区域

  • 选中
    缓存已编译脚本(如果可用)

  • JMeter现在应该向您的请求添加必要的“授权”头


    为什么这项提案被否决了?在官方JMeter认证经理没有的时候为我工作。如果您不想硬编码密码,请添加“vars.get(“appPassword”);”。很好地解释了解决方案。非常感谢。
    name = "username";
    String password = "password";
    String authString = name + ":" + password;
    byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes()); //
    String authStringEnc = new String(authEncBytes);
    sampler.getHeaderManager().add(new org.apache.jmeter.protocol.http.control.Header("Authorization", "Basic " + authStringEnc));