How to add Header values before Posting the HTTP request using LoadRunner

12.5k views Asked by At

I have a Rest webservice for fetching the data from the database. It is using JSON to POST the requests. In the Request Body we pass the required parameters and in Headers we pass the Security token along with other parameters. This Security Token will change every time for each request, which we will be Posting to the server.

I have the DLL which has the logic of generating the security token. The Problem is -> How can i use this DLL so that, EACH time when i run the script from VUgen, it will ADD the Security token parameter in the HEADERS and After that POST the request body. It is something like (in simple words) -> When we run the VUgen script -> The DLL methods will add the Security Token parameter in the Headers and THEN, the Scripts execution will proceed with this security token and Post the request to server.

Could you please let me know, if it is possible to ADD the security token in the PRE Request ? Note -> VUgen script i have created using the Fiddler's .SAZ file and it contains the web_custom_request() method let me know, if you need any more information.

Thanks.

1

There are 1 answers

0
Michael Galos On

It would be something like this:

char securitytoken[1024];
lr_load_dll("token.dll");
securitytoken = securitytokenfunction();
web_add_header("Security-token", securitytoken );
web_custom_request(".....");

Though I would expect trouble getting the securitytoken generating function to work.

It's unusual you will need to keep re-generating the security token on the client side, generally this would be received from the server in the previous request. I highly recommend you verify if that's the case. If so then use parameter correlation instead.

If not then you may want to look at re-implementing the method in your script or fudging the value instead.

Remember that when you load DLLs it is loaded into memory for each virtual user when you execute the test.