使用 Retrofit 发出 Get 请求
Make Get request with using Retrofit
我想使用改装向 Yandex 发出请求
请求的路径是http://geocode-maps.yandex.ru/1.x/?format=json&geocode=latitude%2Clongitude
现在我有了这个:
@GET("/?format=json&geocode={geocode}")
Call<YandexResponse> getGeoCollection(@Path("geocode") String geocode);
当我调用它时出现异常:
URL 查询字符串 "format=json&geocode={geocode}" 不能有替换块。对于动态查询参数,使用@Query.
如何正确提出请求?
@GET("/")
Call<YandexResponse> getGeoCollection(@Query("geocode") String geocode, @Query("format") String format);
那么你应该在函数调用中手动输入格式:
webService.getGeoCollection("address", "json");
我想使用改装向 Yandex 发出请求
请求的路径是http://geocode-maps.yandex.ru/1.x/?format=json&geocode=latitude%2Clongitude
现在我有了这个:
@GET("/?format=json&geocode={geocode}")
Call<YandexResponse> getGeoCollection(@Path("geocode") String geocode);
当我调用它时出现异常:
URL 查询字符串 "format=json&geocode={geocode}" 不能有替换块。对于动态查询参数,使用@Query.
如何正确提出请求?
@GET("/")
Call<YandexResponse> getGeoCollection(@Query("geocode") String geocode, @Query("format") String format);
那么你应该在函数调用中手动输入格式:
webService.getGeoCollection("address", "json");