Hamza2020
Hamza2020

Reputation: 55

How can i pass an array to okhttp android

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.

Upvotes: 1

Views: 831

Answers (1)

Jayanth
Jayanth

Reputation: 6297

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();

Upvotes: 1

Related Questions