Add an array as request parameter with Retrofit 2

后端 未结 7 742
故里飘歌
故里飘歌 2020-12-10 11:04

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:/

7条回答
  •  不知归路
    2020-12-10 11:59

    You need to name your query param with an array syntax like so:

    @GET("http://server/service")
    Observable getSomething(@Query("array[]") List array);
    

    The syntax itself will vary by the backend technology being used, however not including the brackets "[]" will normally be interpreted as a single value.

    For example, using array=1&array=2 will generally be interpreted by backends as only array=1 or array=2 instead of array=[1,2].

提交回复
热议问题