How to send two logically related HTTP requests using jMeter

In the previous article using jMeter to construct a large number of concurrent random HTTP requests , I constructed a large number of concurrent HTTP GET requests through jMeter, which resulted in a large number of read operations on the server.

Now I have another requirement scenario: Suppose I develop a microservice that creates a Service Request, which needs to be called using HTTP post. In order to prevent Cross Site Request Forgery (cross-site domain request forgery), this microservice needs to pass an XSRF token when calling, and this XSRF token needs another HTTP get request to request from the server.

So there are two logically related HTTP requests here:

1. First call HTTP get to read the XSRF token from the server

2. Pass the XSRF token obtained in the first step to the server as a parameter in the HTTP post request header.

How to implement this scene with jMeter?

The general idea is to use the Transaction Controller to package the http get request and the http post request together, as shown in the following figure.

In the first http get request, use the HTTP header parameter x-csrf-token to read the token.

Create a parameter jerrycsrftoken, use regular expressions to parse and save the token returned by the server through the HTTP response header.

Then create a second HTTP post request, and use the parameter jerrycsrftoken created by the first request in the request header.

This is the body content of my HTTP post request, which uses the random number generator that comes with jMeter as the suffix for a successful Service Request.

Finally, the Service Request successfully created using jMeter is displayed in the system as shown in the figure:

To get more original technical articles from Jerry, please follow the public account "Wang Zixi" or scan the QR code below:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325043767&siteId=291194637