I want to run a loadtest on a RestAPI which I can access via below 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);
But in jmeter I am not able add this, new to jmeter please help.
Since JMeter 3.2, Basic Auth is provided Out Of The Box using HttpClient4 implementation and configured by default, see:
HTTP HC4 Implementation now provides preemptive Basic Auth enabled by default
Just add HTTP_Authorization_Manager and fill in required information.
Example:
This configuration will match any request starting with "http://localhost:8081"
See also this question:
Although my answer is downvoted for I don't know which reason, it is the best way to setup Basic Auth. Scripting is no more required at all since 3.2.