If you’ve just started with Apache JMeter, one of the most essential components you’ll come across is the HTTP Request Sampler. It’s the workhorse when it comes to testing the performance of web applications, APIs, and services over HTTP.
In this guide, we’ll break down what the HTTP Request Sampler is, how to use it, and provide a hands-on example to help you get started – even if you’ve never used JMeter before.
- What is an HTTP Request Sampler?
- When to use HTTP Request Sampler?
- How to Add an HTTP Request Sampler in JMeter?
- Configure the HTTP Request Sampler
- Example: Executing a Simple HTTP GET Request
- Example: Executing a Simple HTTP POST Request
- How to Add Headers to a Request
- Other Components of the HTTP Request Sampler
What is an HTTP Request Sampler?
The HTTP Request Sampler is a crucial component in JMeter used to send HTTP/HTTPS requests to a server. It allows you to configure various request parameters, such as the URL, HTTP method (e.g., GET, POST), request headers, and body data. When executed, this sampler sends the request to the specified server and records the response, which aids in analyzing the server’s behavior under test conditions.
When to use HTTP Request Sampler?
You should use the HTTP Request Sampler when:
- Load testing REST APIs
- Verifying that a service or endpoint responds correctly under load
- Measuring response times, errors, and throughput
How to Add an HTTP Request Sampler in JMeter?
Let’s go step-by-step:
- Open JMeter and create a new Test Plan.
- Right-click on Test Plan → Add → Threads (Users) → Thread Group.
- Right-click on Thread Group → Add → Samplers → HTTP Request.
You’ve just added your first HTTP Request Sampler!
Configure the HTTP Request Sampler

As you can see, the HTTP Request Sampler has several fields under the Basic Section. Here’s how you can fill them out:
- Name: Give your sampler a descriptive name, such as “Home Page Request”.
- Server Name or IP: Enter the server’s domain name or IP address, e.g., jsonplaceholder.typicode.com
- Protocol: Specify
http
orhttps
depending on your target URL. - Method: Choose from HTTP methods like GET, POST, PUT, DELETE, etc.
- Path: Define the path to the resource you’re interested in, such as
/posts/1
- Parameters: For requests involving parameters, add them in the ‘Parameters’ section.
- Body Data: Input any body data if the request requires it (commonly used in POST requests).
Example: Executing a Simple HTTP GET Request
As an example, we will try to execute the “https://jsonplaceholder.typicode.com/posts/1
” API using JMeter. This API returns a sample blog post in JSON format.
Steps for Configuration:
- Name: Get Request
- Server Name or IP: jsonplaceholder.typicode.com
- Protocol: https
- HTTP Method: GET
- Path: /posts/1

Now we’re ready to execute our test, but before that, let’s add the ‘View Results Tree‘ listener to visualize the results.

Okay, let’s now click on the Green Run Button to run the Test Plan.

Results
As you can see, the GET request was executed once because we set both the Number of Users and the Loop Count to 1 in the Thread Group
settings. And that’s how you can easily execute a GET request using the HTTP Request Sampler in JMeter.

Example: Executing a Simple HTTP POST Request
Earlier, we executed a GET request. Now, let’s try executing a POST request.
As an example, we will send the payload below to the “https://jsonplaceholder.typicode.com/posts” API using JMeter.
{
"title": "Hello JMeter",
"body": "This is a test post",
"userId": 1
}
Steps for Configuration:
- Name: Post Request
- Server Name or IP: jsonplaceholder.typicode.com
- Protocol: https
- HTTP Method: POST
- Path: /posts
- Select Body Data and paste the Request Payload
{
"title": "Hello JMeter",
"body": "This is a test post",
"userId": 1
}

Click on the Run Button again and observe the results.

We can see that the payload was sent along with the POST request.
How to Add Headers to a Request
There may be scenarios where we need to send a token or other information in the request headers. Let’s take a look at how to set request headers in JMeter.
To set headers with the request, we need to use the HTTP Header Manager.
You can add it by right-clicking on the HTTP Request Sampler → Add → Config Element → HTTP Header Manager.

For now, let’s set a dummy header with the name x-token
and the value codekru
.
Now, click on the Run button and check the results.

Other Components of the HTTP Request Sampler
There are a few other components of the HTTP Request Sampler that we haven’t explored yet. Let’s go through them one by one.
When you’re testing APIs or websites using JMeter, sometimes the server doesn’t give you the final response directly. Instead, it sends a redirect response — like a 301 or 302 — telling your client (JMeter, in this case) to go somewhere else to get the actual content.
This is where the “Follow Redirects” and “Redirect Automatically” options come into play.
Let’s understand both. We’ll use the http://httpbin.org/redirect/3 API, which performs three redirects before finally landing on the http://httpbin.org/get endpoint.
Follow Redirects
- When this option is checked, JMeter will follow the redirects.
- It records both the original request and the redirected request.
- So, you’ll see multiple results in the View Results Tree or logs
Let’s execute the http://httpbin.org/redirect/3 API and check the “View Results Tree” Listener for the responses.
Steps for Configuration:
- Name: Follow Redirect
- Server Name or IP: httpbin.org
- Protocol: http
- HTTP Method: GET
- Path: /redirect/3
- Select the “Follow Redirects” checkbox

Now, run the Test Plan. You’ll notice multiple requests appearing in the ‘View Results Tree’, as shown in the image below.

Redirect Automatically
- When this is checked, JMeter behaves like a browser and automatically follows redirects under the hood.
- Only the final response is recorded.
So, let’s use the same http://httpbin.org/redirect/3 API once again and select the “Redirect Automatically” option this time.

Run the Test Plan.

As you can see, only one entry was recorded, and it displays only the final response.
Follow Redirects vs Redirect Automatically
In Simple Words, the Key Difference:
- Follow Redirects shows you both the redirect and the final destination, step by step.
- Redirect Automatically hides the redirect step and shows you only the final destination.
Let’s again use the http://httpbin.org/redirect/3 API and create two HTTP Request Samplers: one with Follow Redirects enabled and the other with only Redirect Automatically enabled.
Please see the video below for the Test Plan configuration and execution
Here, we can clearly see that the ‘Follow Redirects’ option displays all the intermediate redirects, whereas ‘Redirect Automatically’ only shows the final response.
Port
The Port field in the HTTP Request Sampler specifies the port number to which the request should be sent on the server.

By default:
- HTTP requests use port 80
- HTTPS requests use port 443
If you’re sending requests to these default ports, you can leave the Port field blank, and JMeter will automatically use the appropriate port based on the protocol (HTTP or HTTPS).
However, if the server uses a non-standard port, you’ll need to enter it in this field explicitly.
This is it. We hope that you have liked the article. If you have any doubts or concerns, please write to us in the comments or mail us at admin@codekru.com.