【问题标题】:Yandex Maps return 403 Forbidden using retrofitYandex Maps 使用改造返回 403 Forbidden
【发布时间】:2015-11-24 05:01:42
【问题描述】:

当我在浏览器上调用此链接 https://geocode-maps.yandex.ru/1.x/?format=json&geocode=astana 时,它可以工作,但是当我使用改造调用它时,它给了我 403 Forbidden

我的代码是

Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(Settings.YANDEX_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .client(client)
            .build();
    return retrofit.create(YandexService.class);

public final static String YANDEX_URL = "https://geocode-maps.yandex.ru/1.x";

我用这个来称呼它

@GET("/")
Call<YandexResponse> getGeoCollection(@Query("format") String format, @Query("geocode") String geocode);

还有这个

@Override
public void getMapLocation() {
    Call<YandexResponse> call = dataProvider.yandexSearch("Astana");
    call.enqueue(new Callback<YandexResponse>() {
        @Override
        public void onResponse(Response<YandexResponse> response, Retrofit retrofit) {
        }

        @Override
        public void onFailure(Throwable t) {
            Alert.showDefaultAlert(baseActivity);
            t.printStackTrace();
        }
    });
}

为什么给我403 Forbidden,它不需要任何授权...

【问题讨论】:

    标签: android authorization retrofit yandex-maps


    【解决方案1】:

    我只是将 /1.x/ 从 YANDEX_URL 粘贴到服务

    变成这样

    public final static String YANDEX_URL = "https://geocode-maps.yandex.ru";
    
    @GET("/1.x/")
    Call<YandexResponse> getGeoCollection(@Query("format") String format, 
                                          @Query("geocode") String geocode);
    

    【讨论】:

      猜你喜欢
      • 2012-01-22
      • 1970-01-01
      • 1970-01-01
      • 2021-03-24
      • 2012-08-26
      • 1970-01-01
      • 1970-01-01
      • 2014-06-15
      • 1970-01-01
      相关资源
      最近更新 更多