Home  >  Q&A  >  body text

android - Retrofit API的GET

https://api.heweather.com/x3/weather?cityid=城市ID&key=XXXXXXXXX
这种API 如何用Retrofit 来书写呢

     @GET("x3/weather?cityid={cityid}&key={apikey}")
    Call<WeatherResult> WeatherGet(@Path("cityid") String id,@Path("apikey") String key);
这样写 被提示要使用`@Query("cityid") String id`

Call<WeatherResult> WeatherGet(@Query("cityid") String id,@Path("apikey") String key);


修改完后 又被提示 Path 不能放在 Query后面

那么我想问这样的API 如何写呢

PHP中文网PHP中文网2715 days ago465

reply all(1)I'll reply

  • 阿神

    阿神2017-04-17 17:52:26

    https://futurestud.io/tutoria... According to this, it should be written like this

        @GET("x3/weather")    
        Call<WeatherResult> WeatherGet(@Query("cityid") String id,@Query("apikey") String key);

    Why can’t it be used here? path了,因为这里的api_key是作为查询字符串,所以使用的querypath represents a hierarchical file path.
    Reference resources
    https://zh.wikipedia.org/wiki...

    reply
    0
  • Cancelreply