How to log on to a html page and stay logged in

Hi, I am trying to test a website, it is behind a username and password. If I try to use the documented way to log on, it is fine for the log on page, but if I try to go to another page afterwards, it just sends me back to the log on page.

var url = ‘’;
var payload = JSON.stringify({
TxtUsername: ‘username’,
TxtPassword: ‘password’,
var params = {
headers: {
‘Content-Type’: ‘application/json’,
}, };
http.get(url, payload, params);

This results in a 302 status.

How do I log on to a website, then take that authenticated session and apply it to subsequent calls?

This seems a very standard thing to do but I can not see any examples or help articles on it



Hi @Adam,
Welcome to the forum. The examples for how to implement HTTP authentication in k6 script can be found here:

If your website uses basic authentication, then the 1st example with some modifications should help with that.
Also, please note that http.get can take only 1 or 2 parameters. For reference: