The HTTP Request sampler is the workhorse of JMeter. In the last chapter, you used it to send a simple GET request. But real applications need POST with JSON bodies, file uploads, custom headers, authentication tokens, redirect handling, and timeout configuration. Let us go through each one -- because in interviews, they love asking about these details.
JMeter supports all standard HTTP methods. Most tests use GET and POST, but REST APIs frequently need PUT, PATCH, and DELETE. Think of it this way: if you are testing an e-commerce API, your scenario might be GET /products (browse), POST /cart (add item), PUT /cart/item/1 (change quantity), DELETE /cart/item/1 (remove item).
| Method | Purpose | Has Body? | Example |
|---|---|---|---|
| GET | Retrieve data | No (use params) | GET /api/users?page=2 |
| POST | Create resource | Yes | POST /api/users with JSON body |
| PUT | Replace resource entirely | Yes | PUT /api/users/42 with full user JSON |
| PATCH | Partial update | Yes | PATCH /api/users/42 with {name: "new"} |
| DELETE | Remove resource | Usually no | DELETE /api/users/42 |
| HEAD | Get headers only (no body) | No | HEAD /api/health (check if alive) |
| OPTIONS | Get supported methods (CORS) | No | OPTIONS /api/users (preflight) |
For POST and PUT requests, you need to send a request body. In JMeter, switch to the "Body Data" tab in the HTTP Request sampler. Do NOT use the "Parameters" tab for JSON -- that is for form-encoded data. This is one of the most common beginner mistakes.
{
"username": "testuser_${__threadNum}",
"email": "user${__threadNum}@test.com",
"password": "Test@123",
"profile": {
"firstName": "Load",
"lastName": "Test",
"age": ${__Random(18,65)}
}
}Notice the JMeter functions in the JSON: ${__threadNum} gives the current thread number (so each user has a unique username), and ${__Random(18,65)} generates a random age. This is how you parameterize requests without CSV files for simple cases.
Need to test file uploads? JMeter handles multipart/form-data natively. Use the "Files Upload" tab at the bottom of the HTTP Request sampler.
Set the HTTP method to POST.
Check "Use multipart/form-data" at the bottom of the sampler.
Click the "Files Upload" tab.
File Path: /path/to/test-file.pdf (absolute path on your machine).
Parameter Name: file (whatever the server expects -- check the HTML form or API docs).
MIME Type: application/pdf (or image/jpeg, text/csv, etc.).
Add any additional form fields in the Parameters tab if needed.
When load testing file uploads, every thread uses the same file on disk -- JMeter does not copy it. But each thread reads and sends the file data separately, so memory usage = file_size x active_threads. A 10MB file with 100 threads = 1GB of memory just for file data. Use small test files (100KB-1MB) for load tests.
By default, JMeter follows HTTP redirects (301, 302) automatically. This is usually what you want. But there are two options that behave differently, and knowing the difference matters for your test results.
| Setting | Behavior | Response Time Includes Redirect? | When to Use |
|---|---|---|---|
| Follow Redirects (checked) | JMeter follows redirects automatically | Yes -- total time includes all hops | Default for most tests |
| Redirect Automatically (checked) | Java HTTP client handles redirects | Yes, but intermediate responses are hidden | When you do not need to see redirect details |
| Both unchecked | JMeter returns the 301/302 response as-is | No -- only the first request | When you want to manually handle redirects or test redirect behavior |
Under the "Timeouts" section of the HTTP Request sampler, you can set Connection Timeout and Response Timeout. Think of it like ordering food at a restaurant: Connection Timeout is how long you wait for the waiter to acknowledge you, and Response Timeout is how long you wait for the food to arrive after ordering.
# Connection Timeout (milliseconds)
# How long to wait for TCP connection to establish
# Default: 0 (infinite -- dangerous!)
# Recommended: 5000-10000 (5-10 seconds)
Connect Timeout: 5000
# Response Timeout (milliseconds)
# How long to wait for the full response after connection
# Default: 0 (infinite -- dangerous!)
# Recommended: 30000-60000 (30-60 seconds) depending on your SLA
Response Timeout: 30000
# WARNING: With default 0 (infinite), a hung server means
# your threads never time out. They pile up, JMeter runs
# out of threads, and your test hangs indefinitely.Always set explicit timeouts. The default is 0 (infinite). In a real load test, if the server stops responding, all your threads will hang forever waiting, and your test will never complete. Set connection timeout to 5-10 seconds and response timeout to 30-60 seconds based on your SLA.
When a browser loads a web page, it downloads the HTML and then fetches all embedded resources -- images, CSS, JavaScript. JMeter can do this too. Under "Advanced" tab, check "Retrieve All Embedded Resources" and set "Parallel downloads" to 6 (matching typical browser behavior). This gives you realistic page load times instead of just HTML download times.
For API-only tests (REST APIs, microservices), leave embedded resources unchecked. It is only relevant for web page load tests. If you are testing a React SPA, the initial page load is mostly static assets served from a CDN -- your real test should focus on the API calls the SPA makes.
Q: How do you handle POST requests with JSON bodies in JMeter?
A: I use the Body Data tab, not the Parameters tab. The Parameters tab sends form-encoded data, while Body Data sends raw content. I type or paste the JSON directly into the Body Data field and add an HTTP Header Manager with Content-Type set to application/json. For dynamic data, I use JMeter variables like ${userId} from CSV files or extractors, and JMeter functions like ${__Random(1,100)} for random values. I also make sure to set appropriate timeouts -- Connection Timeout of 5000ms and Response Timeout of 30000ms -- so threads do not hang if the server is slow.
Key Point: Use Body Data tab for JSON (not Parameters tab). Set explicit timeouts. Configure file uploads via the Files Upload tab. Always enable embedded resources for realistic web page tests, but skip it for API tests.
Key Point: HTTP Samplers: Body Data for JSON, Parameters for forms. Set timeouts. Use embedded resources for page load tests only.