JMeter: How to send request with content type header?

后端 未结 2 578
无人及你
无人及你 2021-02-01 11:35

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

相关标签:
2条回答
  • 2021-02-01 12:26

    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.

    0 讨论(0)
  • 2021-02-01 12:31

    Add HTTP Header Manager and add your desired header there:

    0 讨论(0)
提交回复
热议问题