Robin Desbois
Robin Desbois

Reputation: 73

Jmeter: Http POST request with body data and file upload

I'm trying to test a Rest api which is working on postman but not on Jmeter, the request takes (2 parameters):

on Postman : when I put the Content-Type = application/x-www-form-urlencoded, and I upload the json file and the pdf file it works but on jmeter I'm always getting errors such as "Unsupported Media Type"

Upvotes: 7

Views: 12505

Answers (3)

apollov
apollov

Reputation: 147

If you're, like me, were trying to send a file and a JSON in the body togeter to some endpoint, then you should NOT put your JSON into request body, as when you don't send files. Instead, leave Body data field empty, use the parameters tab of Http request / Basic tab, and enter your JSON property name, as it is expected by server, put application/json into Content-type and DON'T check URL encode?.

This is because when you send files, the HTTP request body is used for both your JSON and file data. They're separated by a "boundary string" and both of them must have a name for a server to understand which's where.

Sorry for a bit of necroposting, but this is the only meaningful result I met while googling for "jmeter send file with body".

Upvotes: 1

Rahul
Rahul

Reputation: 336

You can try to add record the network request in Jmeter via postman. I have came across the below link which will do the trick for you

https://www.youtube.com/watch?v=OQWyLMJbXaw

The solution mentioned in the above link actually uses a proxy server in Postman and use the same proxy server in Jmeter test script recorder so that whenever a request is being executed in postman, it travels through Jmeter via proxy.

Upvotes: 2

sunny_teo
sunny_teo

Reputation: 1999

  1. Please check both the requests(Postman and jmeter) are same with all the values header and content type.
  2. Check “Use multipart/form-data for POST” box is not selected.

Use a multipart/form-data or application/x-www-form-urlencoded post request

Reference;-https://jmeter.apache.org/usermanual/component_reference.html#HTTP_Request

For more information, please check this blog.

Hope this helps.

Upvotes: 1

Related Questions