I'm looking for way to add an int array (e.g [0,1,3,5]) as parameter in a GET request with retrofit 2. Then, the generated url should be like this : http://server/service?array=[0,1,3,5]
How to do this ?
You can pass parameter by @QueryMap Retrofit uses annotations to translate defined keys and values into appropriate format. Using the @Query("key") String value annotation will add a query parameter with name key and the respective string value to the request url .
You can send it with help of @FormUrlEncoded for example : @FormUrlEncoded @Headers("Content-Type: application/json") @POST("getclass/") Call<ExampleClass> getExampleClass(@Field("id") int id, @Field("name") String name);
Just add it as a query param
@GET("http://server/service") Observable<Void> getSomething(@Query("array") List<Integer> array);
You can also use int[], or Integer... as a last param;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With