[英]how to use Retrofit2 @POST
我必须从这个 URL https://openweathermap.org/获取数据。
现在我正在使用这些 API
http://api.openweathermap.org/data/2.5/weatherq=(cityname)&appid=(myAPIKEY)
所以我已经在下面的代码工作
这是我的基本网址:
Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").create();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://api.openweathermap.org/data/2.5/")
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
有谁知道如何将 cityName 作为参数传递?
附言。 改造2
您可以使用@Query参数来提供任何参数,如
@GET("weather")
Call<WeatherEnt> getWeatherData(@Query("q") String query,
@Query("units") String units,
@Query("appid") String appid);
并在调用此端点时在这些参数中传递 cityName 和其他值(就像您需要的那样)
你必须像这样改变你的第二种方法:
@POST("http://api.openweathermap.org/data/2.5/weatherq={cityName}&appid=1273091827310988273")
Call<Example> loadPhotoList(@Path("cityName") String cityName);
谢谢大家。 这是一个答案。
@GET("weather") 调用 loadPhotoList(@Query("q") String cityName,@Query("appid") String appid);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.