Retrofit: Send array in POST request

Created on 2 Oct 2015  路  3Comments  路  Source: square/retrofit

How to send array at POST request, example sending body(param->value):
{"chat":["560e8befef36415027432170", "560e8bfabd0a2d2427189eab"]}

I tried make with this method, but not successful:

`
@FormUrlEncoded
@POST("/v1/rooms/{roomId}")

void readMessages(@Path("roomId") String roomId, @Field("chat") String[] ids, Callback callback);

How I make it on Retrofit 1.9.0?
`

Most helpful comment

The format you define is JSON, not form encoding. For this you would create an object with that format like:

class Foo {
  List<String> chat;
}

paired with the @Body annotation on a single parameter.

All 3 comments

how to send a array data,try

@Query("chat[]") String[] ids

The format you define is JSON, not form encoding. For this you would create an object with that format like:

class Foo {
  List<String> chat;
}

paired with the @Body annotation on a single parameter.

thanks this is work for me

Was this page helpful?
0 / 5 - 0 ratings