Knowledgebase

Login Examples


Below we provide a variety of code samples regarding virtual users logging into a system during a test.

Login using HTTP Basic header

1
2
3
4
5
http.request({
  method="GET",
  url="http://example.com/",
  headers={ ["Authorization"]= 'Basic ' .. base64.encode(username .. ':' .. password) }
})

Login using HTTP Basic or Digest authentication

1
2
3
http.request_batch({
     {"GET", "http://username:password@example.com/"}
})

Login using NTLM authentication

1
2
3
http.request_batch({
    {"GET", "http://username:password@example.com/"}
})

If you need to set a domain use the following instead:

1
2
3
http.request_batch({
    {"GET", "http://domain\\username:password@example.com/"}
})

Simple login using HTTP POST

Note: Ideally you should use a data store to provide credentials to variables named login and password. The below example is simplified for sample purposes.

1
2
3
4
5
local post_data = "login=test_user&password=123"

http.request_batch({
     {"POST", "http://test.loadimpact.com/login.php", data=post_data}
})