How to add HTTP headers in JMeter

API and browser load tests often depend on request metadata as much as the URL or payload. In JMeter, the HTTP Header Manager supplies those request headers so HTTP samplers can send JSON content types, accepted media types, authorization values, or application-specific flags at the right scope.

The manager is a configuration element rather than a request sampler. Place it under a Thread Group when several child HTTP samplers need the same headers, or place it directly under one HTTP Request sampler when only that request should receive them.

Multiple HTTP Header Manager elements can apply to the same sampler. JMeter merges their rows for the outgoing request, and a later row with the same header name replaces the earlier value, which makes a shared default plus a sampler-specific override safer than copying every row into every request.

Steps to add a JMeter HTTP Header Manager:

  1. Open the test plan in the JMeter GUI.
  2. Select the scope that should send the headers.

    Select the Thread Group for shared API headers. Select one HTTP Request sampler for request-specific headers.

  3. Add the header manager from AddConfig ElementHTTP Header Manager.
  4. Name the manager for the request group it controls.
  5. Add the required header rows.
    Name: Content-Type
    Value: application/json
    
    Name: Accept
    Value: application/json
    
    Name: X-Test-Scenario
    Value: checkout-smoke

    Use the exact header names expected by the target application. Header names are case-insensitive on the wire, but consistent casing keeps the test plan easier to review.

  6. Keep secret header values in variables instead of literal rows.
    Name: Authorization
    Value: Bearer ${api_token}

    Do not save live bearer tokens, session cookies, or private API keys in a shared .jmx file. Load them from a variable source or command-line property when the plan runs.
    Related: How to add a bearer token header in JMeter

  7. Add request-specific overrides under the sampler that needs them.

    If two applicable header managers define the same header name, the matching row replaces the previous value during the merge. An empty value still sends the header with an empty value; it does not remove the earlier row.

  8. Save the test plan.
    header-manager-add.jmx
  9. Run a one-user non-GUI smoke test.
    $ jmeter -n -t header-manager-add.jmx -l header-manager-results.jtl
    Creating summariser <summary>
    Created the tree successfully using header-manager-add.jmx
    ##### snipped #####
    Waiting for possible Shutdown/StopTestNow/HeapDump/ThreadDump message on port 4445
    summary =      1 in 00:00:00 =   11.5/s Avg:    16 Min:    16 Max:    16 Err:     0 (0.00%)
    Tidying up ...
    ... end of run
  10. Check the result file for a successful sample.
    $ cat header-manager-results.jtl
    timeStamp,elapsed,label,responseCode,responseMessage,threadName,dataType,success,failureMessage,bytes,sentBytes,grpThreads,allThreads,URL,Latency,IdleTime,Connect
    1782776110247,16,POST /checkout,200,OK,Checkout API smoke users 1-1,text,true,,107,254,1,1,https://api.example.net/checkout,13,0,11
  11. Check the target server log or request inspector for the received headers.
    $ cat header-echo-server.log
    method=POST path=/checkout content_type=application/json accept=application/json x_test_scenario=checkout-smoke status=200