Retrofit error URL query string must not have repl

2019-03-14 10:32发布

I have this function

      @GET("/users?filters[0][field]={param}&filters[0][operator]=equals&filters[0][value]={value}")
UserDto retrieveUsersByFilters(@Path("param") String nameFilter, @Path("value") String value);

I try to call it like this :

   UserDto currentUser = interfaceUser.retrieveUsersByFilters(User.LOGIN, login);

But i have error :

retrofit.RetrofitError: InterfaceUser.retrieveUsersByFilters: URL query string "filters[0][field]={param}&filters[0][operator]=equals&filters[0][value]={value}" must not have replace block.

I already test url on firefox and it work fine.

Thank's for your responses

Edit

Solution:

          @GET("/users?filters[0][operator]=equals")
          UserDto retrieveUsersByFilters(
          @Query("filters[0][field]") String nameFilter,
          @Query("filters[0][value]") String value);

3条回答
女痞
2楼-- · 2019-03-14 11:28
 URL="/api-mobile_prateek2.php?method=getProductById&pid="


 @GET("/api-mobile_prateek2.php?method=getProductById")
    Call<Product> responseproduct(@Query("pid") String pid);

dont put the pid in the @GET,, Retrofit automatically fix the url, using @Query

查看更多
Bombasti
3楼-- · 2019-03-14 11:32

Query params have their own annotation which automatically appends to the URL.

@GET("/users?filters[0][operator]=equals")
UserDto retrieveUsersByFilters(
    @Query("filters[0][field]") String nameFilter,
    @Query("filters[0][value]") String value);

You can read more about @Query on its Javadoc

查看更多
闹够了就滚
4楼-- · 2019-03-14 11:38

Don't put your values directly in the path, but prefer in the method signature. Not completely sure, but try something like this :

@GET("/users?filters[0][operator]=equals")
UserDto retrieveUsersByFilters(@Path("filters[0][field]") String nameFilter, @Path("filters[0][value]") String value);
查看更多
登录 后发表回答