1

I want to pass an array as parameter in okhttp.I just tried like

RequestBody formBody = new FormBody.Builder()
.add("customerId", "0000000003")
.add("storeId","rayban") 
.add("items[]",array.toString())
.build();

I want to pass the items array to the form builder . but i cant pass the array to the api.how can i do this.how to pass an array to okhttp.

Hamza2020
  • 55
  • 1
  • 9
  • Does this answer your question? [How to add array to okhttp body (POST)](https://stackoverflow.com/questions/33307395/how-to-add-array-to-okhttp-body-post) – shb May 16 '20 at 07:14

1 Answers1

1

You can send like below

FormBody.Builder builder = new FormBody.Builder();
builder.add("customerId", "0000000003")
builder.add("storeId","rayban") 
for(int i = 0; i < array.length; i++){ 
  builder.add("items[" + i + "]", array[i])
}

FormBody body = builder.build();
Jayanth
  • 5,954
  • 3
  • 21
  • 38