具有基本身份验证的Jmeter
我想在RestAPI上运行loadtest,我可以通过下面的java访问它具有基本身份验证的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
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实现提供的,并在默认情况下进行配置,请参阅:
- 要将此请求发送到“”:
- 配置将是:
虽然我的答案被否决了,但我不知道是什么原因,这是设置基本身份验证的最佳方式。自3.2版以来,不再需要编写脚本。您可以使用相同的代码生成编码凭据:
缓存已编译脚本(如果可用)
框为什么这项提案被否决了?在官方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));