In the previous article using JMeter to construct a large number of concurrent random HTTP requests, I constructed a large number of HTTP get concurrent requests through JMeter, which generated a lot of read operations on the server.
Now I have another requirement scenario: Suppose I have developed a microservices that creates service requests and needs to use an HTTP POST call. In order to prevent cross site request forgery, which requires a XSRF token for this microservices invocation, this XSRF token requires another HTTP GET request from the server.
Therefore, there are two logically related HTTP requests:
1. Call HTTP GET to read XSRF token from the server first
2. Pass the XSRF token obtained in the first step to the server as a parameter to the HTTP POST request header.
How to achieve this scene with JMeter?
The general idea is to use the transaction Controller to package the HTTP GET request with the HTTP POST request, as shown in.
In the first HTTP GET request, use the HTTP header parameter X-csrf-token to read token.
Create a parameter jerrycsrftoken, using regular expressions to parse and save the token returned by the server through the HTTP response header.
It then creates a second HTTP POST request, which is jerrycsrftoken with the parameter created by the first request on the request header.
This is the body content of my HTTP POST request, which uses the JMeter random number generator as the suffix to create a successful service request.
The last service request that was successfully created using JMeter is displayed in the system
To get more original Jerry's technical articles, please follow the public number "Wang Zixi" or scan the QR code below:
How to use JMeter to send two logically related HTTP requests