JMeter 5.0: How to send HTTP Request with body data?

This may be a duplicate from

But despite the guys on that question claiming it is solved on version 3.1 of JMeter, it is not working as I expected on JMeter 5.0.

I also tried to set Content-Type: application/x-www-form-urlencoded on a HTTP Request Manager associated to the HTTP Request Sampler but the body is only passed on POST requests. My app receives nicely from Postman but not from JMeter.

EDIT: This is the Code snippet generated by Postman:GET /api/patients/5c1e35351f68df799c0ad864/cases HTTP/1.1 Host: localhost:3080 Content-Type: application/json Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6InJ1YmVubWFycXVlczkxQGdtYWlsLmNvbSIsInVzZXJJZCI6IjVjMjNiZTJkNjU0YjIwMzhiNDQwY2ViZiIsImlhdCI6MTU0NjAxMjQ2NSwiZXhwIjoxNTQ2MDE2MDY1fQ.LqCV9eHByxQ0ubDIcJOwR0WGGXfMw49X0VLLurjbseM cache-control: no-cache Postman-Token: 2d8f4f4c-4ec6-428e-bf1a-cafd27fa98ed { "caseName": "TestName" }------WebKitFormBoundary7MA4YWxkTrZu0gW--

2 Answers

What exactly doesn't work? For example, given the following Elastic search payload:

{ "index": { "_index": "shakespeare", "_type": "act", "_id": 0 }
}
{ "line_id": 1, "play_name": "Henry IV", "speech_number": "", "line_number": "", "speaker": "", "text_entry": "ACT I"
}

When I execute the following GET request:

{ "query": { "match": { "play_name": "Henry IV" } }
}

enter image description here

I can see the request body exactly as I defined in the View Results Tree listener

enter image description here

And the response contains all the relevant search results:

enter image description here


So I would recommend comparing the requests which are being sent by Postman and JMeter using a sniffer tool like Fiddler or Wireshark. Most probably there is an error in JMeter configuration, presumably connected with wrong Content-Type


Also be aware that it is possible to record the request sent from Postman using JMeter's HTTP(S) Test Script Recorder

  1. Prepare JMeter for recording. The easiest way of doing this is using JMeter Templates feature

    • from JMeter's main menu choose File -> Templates -> Recording and click "Create"
    • Open HTTP(S) Test Script Recorder and click "Start"
  2. Prepare Postman for recording

    • from Postman main menu choose File -> Settings -> Proxy
    • tick both HTTP and HTTPS protocols and set proxy server to 127.0.0.1:8888

      enter image description here

  3. Execute your request in Postman

  4. JMeter should capture it under the Recording Controller. If everything goes well you should be able to replay it without any issues.
10

The problem was in the configuration o JMeter. I was using the Parameters tab of HTTP request and putting properties on the Name tab and values on the Value tab.

An illuminated user posted this: .

I don't know why my initial approach worked on POST, PATCH and PUT requests and not on GET requests specifically, but now I'm just sticking with putting the body of all my requests on the Body Data tab and creating a Header with Content-Type: application/json because THAT works!

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like