How To Send JMeter POST Requests

How To Send JMeter POST Requests

In many cases, even an ordinary load test contains lots of different requests for different services. If you need to perform a load test…

How To Send JMeter POST Requests

In many cases, even an ordinary load test contains lots of different requests for different services. If you need to perform a load test for an end-to-end scenario, you’ll probably be dealing with lots of POST requests as well. Luckily, JMeter has the flexibility to create your JMeter POST requests easily.

But to send JMeter POST requests to a specific service, you need to know how to use that service. Because there will be some parameters/body data to be filled, custom-header to manipulate etc. If you haven’t written that service or don’t have any information about that, you should get in contact with the right people, so that you’ll know how to send a proper request.

When you are working with a customer, they can send you an API documentation, Postman collection etc. If they don’t have any of these, you should organize a small meeting with IT experts to understand the concept of that service. Heuristic approach could be really time consuming.

In this article we will be talking about a POST request for reqres.in, which is a dummy API website. Let’s get started!

Create a Test Plan First For JMeter Post Requests

As you know, if you don’t open an existing project, a blank Test Plan content welcomes you on JMeter. So, let’s add a Thread Group first. Just right click on Test Plan and then click on the element by following this path: Threads (Users) -> Thread Group. Your Thread Group should be added now. And you can keep values in Thread Properties as they are.

The second thing to do, is to add an HTTP Request Sampler into our Thread Group, which we will be using for sending our POST request.

You can add your HTTP Request Sampler by following the path above. After that, we need to configure this HTTP Request as a POST request.

Configure Your HTTP Request Sampler

You can configure your HTTP Request as a POST request just like in the image below.

Changing the method will simply do the trick. After that, we need to choose a service from reqres.in, so let’s open the website.

When you scroll down a bit, you’ll see a POST request with the name of “REGISTER — SUCCESSFUL”. If you click on the request, you can see the example request & response couple for a successful Register POST Request.

To make a successful /api/register call, your request should be like in the picture above. And before filling the body data, we need to configure the server’s name and path for our request on JMeter. So, let’s go back to JMeter.

We know that our base URL is https://reqres.in, so we should take the HTTPS part as our protocol and the rest should be our server’s name. 443 is the standard port number for secure transfers in HTTPS traffic. And thanks to reqres.in, we know that our Register request will be sent to /api/register path.

Attention: Since this website serves as a dummy API platform, no advanced Header manipulation or usage is needed. But in real scenarios, a request is usually sent with a Header part that contains different keys.

To add Header to your HTTP Request, just click on the element by following this path: “Right click on HTTP Request” -> Add -> Config Element -> HTTP Header Manager. After that, you’ll see that your custom-header manager is added into your request. Let’s click on that and add some Header keys.

As you can see, we added some Header keys for our HTTP Request Sampler. Content-Type: application/json indicates that the request body format will be JSON. Accept: application/json key allows you to ask the server a JSON format.

The other two keys are also very popular as well. Now let’s continue with preparing our body data.

Body data for a POST request contains the information that will be sent to the server. And for our /api/register service, we need to add email and password keys to our body data. So, let’s do that.

And as you can see, we added body data to our HTTP Request, according to API documentation provided by reqres.in. You can also add these body data keys as parameters, it’s up to you. But don’t change the email and password values, since this is an example dummy service.

Add a Listener and Run the Test

Right now, everything looks good to run this test. So, before we start our test run, let’s add a View Results Tree to our Thread Group. Do this by following this path: “Right Click on Thread Group” -> Listener -> View Results Tree

Save your test plan to your local drive and click on the start button. You should be able to see a successful request, just like in the image below.

If you are provided with “id” and “token” keys in Response Json, congrats! You just made successful JMeter POST requests to your /api/register service.

And that’s it! We have just explored how to send a simple JMeter POST requests.