Yandex 天气 403 禁止 API

403 Forbidden in Yandex Weather API

我需要创建一些应用程序。这个应用程序显示天气预报。 Google 天气 API 不见了。但是 Yandex 有这个 API.My 代码是正确的,但是这个 api 我有一些问题。在示例中写:https://api.weather.yandex.ru/v1/forecast?geoid=213&l10n=true. But this example return 403.https://api.weather.yandex.ru/v1/forecast?geoid=2&lang=ru_RU also return 403.But once it return forecast then it returns 403.

如果您使用 HttpURLConnection,可能缺少 header 的某些参数(如 content-typeencoding)。可能 HttpURLConnection 应该配置成 setRequestMethod("GET"); 或类似的东西:HTTP 身份验证、代理、Cookie 等等(看看 Official Documentation)。