How to add an array to okhttp body (POST)

Now I add the array as a string to the body:

RequestBody body = new FormEncodingBuilder() .add("profiles", "[122, 125, 336]") .build(); 

But the server needs an array with the post parameter. How to add an array instead of a string? Is this possible with okhttp?

+5
source share
1 answer

You are currently sending profiles as a string. You will want to reproduce the POST for the checkbox form field for profiles

 RequestBody body = new FormEncodingBuilder() .add("profiles[0]", "122") .add("profiles[1]", "125") .add("profiles[2]", "336") .build(); 

more information and good reading,

+4
source

Source: https://habr.com/ru/post/1234391/


All Articles