126

How can we change content type in request header of HTTP request for restful web services? From where do we exactly change it?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Thonas1601
  • 1,347
  • 2
  • 9
  • 11
  • I think it is a good question! I'm using django, and can see the values I set in the header section appear under the GET map inside my request. However, I expected it under META. No idea how to get it there.. – Ward Oct 15 '13 at 18:55

4 Answers4

191

Add HTTP Header Manager and add your desired header there:

Header Manager with Content-Type header

UBIK LOAD PACK
  • 33,980
  • 5
  • 71
  • 116
Andrei Botalov
  • 20,686
  • 11
  • 89
  • 123
23

TL;DR To add Content type header you must have HTTP Header Manager associated to HTTP Request


You must add it for :

GET, DELETE, PUT and PATCH require a Content-Type.

Without overriding your request will be sent with defaults as:

Connection: keep-alive
Content-Length: [length of body]
Content-Type: text/plain
Host: [your host]
User-Agent: Apache-HttpClient/4.5.7 (Java/1.8.0_191)

Unlike using postman (advantage over JMeter), where you choose your content type in the same component, In JMeter you must have HTTP Header Manager which can be added as

  1. Child component of HTTP Request - effect only one request
  2. Same or above HTTP Request's hierarchy - may/will impact other HTTP requests in scope

Notice you can have multiple Header Managers:

JMeter now supports multiple Header Managers. The header entries are merged to form the list for the sampler. If an entry to be merged matches an existing header name, it replaces the previous entry. This allows one to set up a default set of headers, and apply adjustments to particular samplers. Note that an empty value for a header does not remove an existing header, it just replace its value.

Notice you can't use it in multipart/form-data:

When using multipart/form-data, this suppresses the Content-Type and Content-Transfer-Encoding headers; only the Content-Disposition header is sent.

It won't be sent it in redirected urls:

Headers are sent for the initial request, and won't be sent for the redirect. This is generally only a problem for manually created test plans, as a test plan created using a recorder would continue from the redirected URL.

Ori Marko
  • 56,308
  • 23
  • 131
  • 233
6

Steps to add HTTP Headers

  • Create an HTTP Request

Thread Group -> HTTP Request

  • Right-click on the HTTP Request and add config element "HTTP Header Manager"

HTTP Request -> Add -> Config Element -> HTTP Cache Manager

enter image description here

Rajesh
  • 4,273
  • 1
  • 32
  • 33
1

Via JMeter UI you can add Request Header:

  • Thread group scope:

Thread group(right-click)-> Add-> Config Element -> HTTP Header Manager enter image description here

  • Request scope (@Override Thread group scope):

request (right-click)-> Add-> Config Element -> HTTP Header Manager enter image description here