user2626431
user2626431

Reputation: 457

JMeter Multipart JSON Request Form Data

I am trying to construct a HTTP Request through JMeter that uses a multipart data body.

I have a HTTP Header Manager that has COntent-Type set to multipart/form-data; boundary=AaB03x. I selected 'Use multipart/form-data for POST'.

I then have a data body created as,

`-----------------------------AaB03x
Content-Type: application/json
Content-Disposition: form-data; name="part1"
{"jsonKey1": "JsonValue1" }

-----------------------------AaB03x
Content-Type: application/json
Content-Disposition: form-data; name="part2"
{ 
  "jsonKey2": "JsonValue2"
}

-----------------------------AaB03x
Content-Type: application/octet-stream
Content-Disposition: form-data; name="part3"
File Content here!!!!

-----------------------------AaB03x`

When I run this, I see that the request doesnt send the body correctly, instead it just sends some random data as,

POST data:

--vKOghkU7riRQbaANmmGpMs7j9TxCTUp3S2T0vE--

And gives an error response of,

`{"errorMsg":"Unable read headers from MultipartStream.","messageCode":"UnableReadHeadersFromMultipartStream","httpStat     us":"BAD_REQUEST","requestName":"RequestName"}`

My second question is: the part3 of the request sends a file to upload. Can I pass the file path somehow?

Upvotes: 2

Views: 9304

Answers (2)

Iske
Iske

Reputation: 1200

You should try sending your JSON data as parameters. Also put your file path in the section for that... And even some servers don't actually need MIME type explicitly declared, you can check yours with some online tool like this one.

Your HTTP Request could look smethnig like:

enter image description here

Upvotes: 1

Dmitri T
Dmitri T

Reputation: 168157

  1. Given you set your own boundary and build your request manually I believe you need to uncheck Use multipart/form-data for POST in the HTTP Request Sampler
  2. If your file encoding isn't very "exotic" you can try using __FileToString() function just instead of File Content here!!!!.

Looking into RFC 7578, it seems you also need a trailing -- at the end of the last line

Upvotes: 1

Related Questions