JMeter Multipart JSON Request Form Data

jmetermultipartform-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?

Best Answer

  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

Related Topic