In the previous article using jMeter to construct a large number of concurrent random HTTP requests, I used jMeter to construct a large number of concurrent HTTP GET requests, which generated a large number of reads to the server.
Now I have another requirement scenario: Suppose I develop a microservice that creates a Service Request and requires an HTTP POST call. To prevent Cross Site Request Forgery, this microservice call requires passing an XSRF token, which requires another HTTP GET Request from the server.
Therefore, there are two logically related HTTP requests:
1. Call HTTP GET to read the XSRF token from the server
2. Send the XSRF token obtained in the first step to the server as a parameter in the HTTP POST request header.
How do you implement this scenario with jMeter?
The idea is to use the Transaction Controller to bundle HTTP GET and HTTP POST requests together, as shown in the figure below.
In the first HTTP GET request, the HTTP header parameter X-CsrF-token is used to read the token.
Create a parameter jerryCsrfToken that uses a regular expression to parse and save the token returned by the server through the HTTP response header.
A second HTTP POST request is then created using the parameter JerryCsrfToken created in the first request in the request header.
This is the body content of my HTTP POST Request, which uses jMeter’s own random number generator as the suffix for a successful Service Request.
Finally, the Service Request successfully created by jMeter is displayed in the system as shown in the figure below:
For more of Jerry’s original technical articles, please follow the public account “Wang Zixi” or scan the following QR code: