Jmeter: Http POST request with body data and file upload
Asked Answered
G

3

7

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

  • a pdf file
  • a body data (json containing pdf information)

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"

Ginter answered 31/5, 2019 at 10:12 Comment(1)
have you found a solution for this? I am fighting with the same problem and no luck with Jmeter.Alabaster
D
2

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.

Driskill answered 1/6, 2019 at 9:30 Comment(0)
B
1
  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.

Blitzkrieg answered 31/5, 2019 at 13:16 Comment(0)
B
1

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".

Blindfold answered 16/11, 2023 at 18:16 Comment(2)
Hello apollov, do you have a screenshot? Thanks.Ylem
@Ylem snipboard.io/1FHQUx.jpg snipboard.io/xotqM5.jpgBlindfold

© 2022 - 2024 — McMap. All rights reserved.