How can we change content type in request header of http request for restful web services? From where do we exactly change it?
2 Answers
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
- Child component of HTTP Request - effect only one request
- 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.