Yandex Maps return 403 Forbidden using retrofit

风格不统一 提交于 2019-12-12 19:14:36

问题


When I call this link https://geocode-maps.yandex.ru/1.x/?format=json&geocode=astana on my browser it works, but when I call it using retrofit It gives me 403 Forbidden

My code is

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";

I call it using this

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

and this

@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();
        }
    });
}

Why it gives to me 403 Forbidden, it doesn't need any authorization...


回答1:


I Just paste /1.x/ from YANDEX_URL to Service

become this

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);


来源:https://stackoverflow.com/questions/33885802/yandex-maps-return-403-forbidden-using-retrofit

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!