Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add array to okhttp body (POST)

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?

like image 941
illuzor Avatar asked Oct 23 '15 16:10

illuzor


1 Answers

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,

  • https://teamtreehouse.com/community/how-to-handle-multiple-checkboxes-values-in-a-form-using-php
  • Get $_POST from multiple checkboxes
like image 90
petey Avatar answered Nov 13 '22 14:11

petey