'How to send multipart/form data with array from Java?

When I use Postman, I send a request like "form-data", and it works.

I know how to make a request, but I do not know how to assemble the body of such a request.

enter image description here

The resource to which I should send the post request expects this format:

array 
(
   "data" =>  array
        (
            0 =>  array 
            (
                "external_id" => 123, 
                "count"       => 1,
                "price"       => 1000,
            ),
        1 =>  array 
            (
                "external_id" => 345,
                "count"       => 2,
                "price"       => 2000,
            ),
        2 =>  array 
            (
                "external_id" => 456,
                "count"       => 3,
                "price"       => 3000,
            ),
    ),

)

Thanks for any help.



Solution 1:[1]

have you tried with this in raw format?

I think when it comes to JSON structures a PHP array is taken like a JSON object. So what you would need to do here is to put all your JSON inside a data field of content-type application/json as shown in this screenshot and it should work. Let me know how it goes. postman screenshot

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 A.Lorefice