Answered question

How can I add an authorization header with an HTTP Get call?

I have a python test that I would like to replicate within Neoload. The script consists of two basic actions:

1. Within an Http request - how do I provide Basic authentication credentials?
2. Within an Http request - how do I provide / obtain the authorization token from a previous request?

Within Neoload, under my Virtual User, I have created two Web Pages - with each Web Page having it own Http Request.

The following is an example of the design structure.

GetProjects (Virtual User)
-- Init (Folder)
-- Actions (Folder)
---- Authentication (Web Page)
-------- /authentication/v1/login (Http Request)
---- GetProjects (Web Page)
-------- /api/v1/projects (Http Request)
-- End (Folder)

The following is the sample python test that I am trying to replicate within Neoload:
-------------------------------------------------------------------------------------------------------------
import requests

USER = 'aosman-author'
PASSWORD = 'aosman'

# Authenticate
loginRequest = requests.get('http://localhost:59499/authentication/v1/login'; , auth=(USER, PASSWORD))
LoginHeader = {'authorization': loginRequest.headers['authorization'], 'Content-Type': 'application/json'}

# REST API Call
r = requests.get('http://localhost:59499/api/v1/projects/1374265';, headers=LoginHeader)
-------------------------------------------------------------------------------------------------------------

Any assistance or guidance is greatly appreciated.

Areag O.
Areag O.

Areag O.

Level
0
42 / 100
points
Areag O.
Areag O.

Areag O.

Level
0
42 / 100
points

After lots of trail and error - I was able to answer my own questions. Posting answers, incase anyone else has the same questions.

1) For the first Http Request, basic authentication can be defined within the 'Request headers' tab that is found within the Advanced settings of an Http Request. Here, one needs to specify a request header that is similar to:

Name: Authorization
Value: Basic <base64 encoding of username:password>

2) To obtain the authorization token that is generated by the first Http request, within the 'Variable extractor' tab of the Advanced settings of this request, one needs to define a variable that represents this token.

Variable Name: ApplicationToken
Regular Expression: "(.*?)"
Template: $1$

In order to add this token to the second Http Request, the request headers defined within advanced setting of this request need to be updated.

Name: Authorization
Value: ApplicationToken ${ApplicationToken}

Did you find this useful ?

No (1)

Yes (1)

50%

50% of users found this answer useful

Other answers

Normally if you add your credentials in the server definition in NeoLoad with your realm if any, during the replay NeoLoad will add for you that authentication header with the Base64 value.

You can look at the NeoLoad documentation here