Reputation: 711
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"
}
Upvotes: 70
Views: 124440
Reputation: 19
I was facing the similar issue, the size of my request body was also huge so along with updating content-type as application/json, i gave content encoding as utf-8 and it worked perfectly fine.
Upvotes: 0
Reputation: 320
If none of the abovementioned solutions work for you (as it was for me) take a second look at the HTTP Header Manager. I had empty header line there
Removing it solved the problem
Upvotes: 4
Reputation: 557
Yes, we need to pass the Content-Type header. I faced the same issue and it took nearly a day to figure out until I came across this link - https://www.blazemeter.com/blog/performance-test-web-services
Header:
Name: Content-Type
Value: application/json;charset=utf-8
Upvotes: 4
Reputation: 129
HTTP Header Manager: Name: Content-type and Value: application/json has resolved issue.
Upvotes: 0
Reputation: 5
Insert your json in body data
field.
In your HTTP Header Manager
set the headers stores
to:
"name" :
Content-Type
"value":
application/json
Upvotes: 0
Reputation: 1029
I had given HTTP/1.1 415 Unsupported Media Type
After deleting space before of HTTP Header Manager ,It got 200 and worked like a charm
Upvotes: 2
Reputation: 189
In addition to many said above, make sure that the copy/paste of Accept, Content-Type from website doesn't have a trailing space! It costs me many hours to figure it out. Just a caution.
Just edit to add that if that mistake happens, return code is 415: Unsupported Media Type
Upvotes: 1
Reputation: 847
First thing you might wanna do is put the payload inside "Body Data" Instead of "Parameters"
Then, add a config element "HTTP Header Manager" And add a parameter "content-type" With corresponding value "application/json"
Now hit. Should do!
Upvotes: 6
Reputation: 11449
Though Hasiya explain really well but missed how to find http request. If you chose http default will not see method option .
Upvotes: 1
Reputation: 149
This solution from Dmitri T, really worked for me.
Make sure your HTTP Header Manager is configured to send "Content-Type" header with the value of "application/json".
Upvotes: 14
Reputation: 101
I have faced the same issue and it was resolved by setting the value of Content Encoding to utf-8 in http request. Please try.
Upvotes: 10
Reputation: 1458
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
Upvotes: 135
Reputation: 711
I figured out my problem. I had set Content_type instead of Content-Type so it was creating two content type headers.
Upvotes: 1
Reputation: 477
As per your attached pic , You have pasted the request in queryparameters , the payload must be in body part
check the screenshot you have payload in queryParam section
Upvotes: -1
Reputation: 253
You must use body data, not parameters. cut and paste it the next tab on your request. Also you should change implementation to Java and check if your token is valid. Finally check your results from view results tree reporting item. It must be work for you.
Upvotes: 0
Reputation: 168072
Content-Type
header with the value of application/json
Check out Testing SOAP/REST Web Services Using JMeter for more tips.
Upvotes: 20