I am trying to do a POST in jmeter with a json as the body data but I just get a 400 back. The URL I am sending to only accepts json. I have used the same curl in Postman and it worked just fine. I have tried putting the json in the parameters as a value with no name and that didnt work.
I am just trying to send {"uid":"jmtest","name":"newdevice"}.
Sorry I cant post more links.
The sampler result is
Thread Name: QA test 1-1 Sample Start: 2016-05-11 11:50:19 MDT Load time: 86 Connect Time: 51 Latency: 86 Size in bytes: 282 Headers size in bytes: 244 Body size in bytes: 38 Sample Count: 1 Error Count: 1 Data type ("text"|"bin"|""): text Response code: 400 Response message: Bad Request Response headers: HTTP/1.1 400 Bad Request Server: nginx Date: Wed, 11 May 2016 17:50:19 GMT Content-Type: application/json; charset=utf-8 Content-Length: 38 Connection: keep-alive X-Request-Id: 88339ee9-b74f-4e22-b581-e3124949d067 X-Runtime: 0.030877 HTTPSampleResult fields: ContentType: application/json; charset=utf-8 DataEncoding: utf-8
And the request looks like
/url redacted POST data: {"devices":{"uid":"jmtest","name":"newdevice"} [no cookies] Request Headers: Connection: keep-alive Accept: application/vnd.moneydesktop.v2+json Content_Type: application/json MD-SESSION-TOKEN: redacted Content-Type: application/x-www-form-urlencoded Content-Length: 46 Host: redacted User-Agent: Apache-HttpClient/4.5.2 (Java/1.8.0_72)
The response data is
{ : "status":"400", : "error":"Bad Request" }
To perform sending the JSON payload we need a different configuration. First, we need to add HTTP Header Manager into our HTTP Request in order to set Content-Type as application/json. We then put the JSON payload into the Body Data section of our HTTP Request Sampler.
To post JSON to a REST API endpoint, you must send an HTTP POST request to the REST API server and provide JSON data in the body of the POST message. You also need to specify the data type in the body of the POST message using the Content-Type: application/json request header.
Create a Test Plan First For JMeter Post Requests Just right click on Test Plan and then click on the element by following this path: Threads (Users) -> Thread Group. Your Thread Group should be added now. And you can keep values in Thread Properties as they are.
JSON Extractor- It is a handy tool to execute JSON Path expressions against JSON responses and storing the result into a JMeter Variable. If the response of any request is in JSON then we can use this extractor. Let's see how can we use it in our script to extract the values from JSON.
To send a POST HTTP Request with the JSON Data inside the body, need to add,
Image 1:Set HTTP Header Manager,
Image 2:Set HTTP Request Body Data
Content-Type
header with the value of application/json
Check out Testing SOAP/REST Web Services Using JMeter for more tips.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With