How to use JMeter to send two logically related HTTP requests

Source: Internet
Author: User
Tags http post

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.