8

Now i`m adding array as string to body:

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

But the server need array on post parameter. How can i add array instead of string? Is it posible with okhttp?

illuzor
  • 615
  • 9
  • 19

1 Answers1

8

You are currently posting profiles as a string. You will want to mimic a POST for a checkbox form field for profiles

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

more info and good reading,

Community
  • 1
  • 1
petey
  • 16,914
  • 6
  • 65
  • 97
  • What if the array is dynamic? – emen Aug 02 '16 at 08:32
  • 2
    is the array is dynamic, use a loop. – petey Aug 02 '16 at 13:46
  • @BhavikMehta No. I'm not dumb, Arrays can also be immutable. This answer shows the OP a simple way to send form values to their backend as an array called 'profiles'. Please undo your down vote – petey Mar 21 '18 at 16:15