Ala*_*lan 52 java android retrofit retrofit2
我使用查询参数来设置Google Maps API所需的值.
问题是我不需要&第一个查询参数的符号.
@GET("/maps/api/geocode/json?")
    Call<JsonObject> getLocationInfo(@Query("address") String zipCode,
                                             @Query("sensor") boolean sensor,
                                             @Query("client") String client,
                                             @Query("signature") String signature);
改造产生:
&address=90210&sensor=false&client=gme-client&signature=signkey
当我需要它时,会导致调用失败
address=90210&sensor=false&client=gme-client&signature=signkey
我该如何解决?
And*_*eas 79
如果你指定@GET("foobar?a=5"),那么任何@Query("b")必须附加使用&,产生类似的东西foobar?a=5&b=7.
如果你指定@GET("foobar"),那么第一个@Query必须附加使用?,产生类似的东西foobar?b=7.
这就是Retrofit的工作原理.
当您指定时@GET("foobar?"),Retrofit认为您已经提供了一些查询参数,并使用添加更多查询参数&.
删除?,您将获得所需的结果.
Tab*_*mos 37
我是新来的改造,我很享受.因此,对于那些可能想要使用多个查询进行查询的人来说,这是一种简单的方法来理解它:和&会自动为您添加.
接口:
 public interface IService {
      String BASE_URL = "https://api.test.com/";
      String API_KEY = "SFSDF24242353434";
      @GET("Search") //i.e https://api.test.com/Search?
      Call<Products> getProducts(@Query("one") String one, @Query("two") String two,    
                                @Query("key") String key)
}
它将以这种方式调用.考虑到你已经完成了其余的代码.
  Call<Results> call = service.productList("Whatever", "here", IService.API_KEY);
例如,当返回查询时,它将如下所示.
//-> https://api.test.com/Search?one=Whatever&two=here&key=SFSDF24242353434 
 public interface IService { 
  String BASE_URL = "https://api.demo.com/";
  @GET("Login") //i.e https://api.demo.com/Search? 
  Call<Products> getUserDetails(@Query("email") String emailID, @Query("password") String password)
} 
它将被称为这种方式。考虑到您已经完成了其余的代码。
Call<Results> call = service.getUserDetails("abc@gmail.com", "Password@123");
例如,当返回查询时,它将看起来像这样。
https://api.demo.com/Login?email=abc@gmail.com&password=Password@123
| 归档时间: | 
 | 
| 查看次数: | 70989 次 | 
| 最近记录: |