android - Retrofit API的GET
本文介绍了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 如何写呢
解决方案
https://futurestud.io/tutoria... 根据这个来看应该就是这么写吧
@GET("x3/weather")
Call<WeatherResult> WeatherGet(@Query("cityid") String id,@Query("apikey") String key);
这里的为什么不能使用path
了,因为这里的api_key
是作为查询字符串,所以使用的query
,path
代表的是带层次的文件路径。
参考资源
https://zh.wikipedia.org/wiki...
这篇关于android - Retrofit API的GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文