首页 > 解决方案 > 从 Openweathermap 获取请求返回 (404) 未找到

问题描述

我正在尝试使用以下代码获取天气信息,但每次(除了第一次,但我不确定)我都会收到 404 响应。我做错了什么?

CityName = "鄂木斯克"; API_KEY = "368e827be4b38db51ff960ca88b5c396";

        weburl = "http://api.openweathermap.org/data/2.5/weather?q=" + CityName + "&mode=xml&APPID=" + API_KEY;
        //weburl = "http://api.openweathermap.org/data/2.5/forecast?id=524901&APPID=368e827be4b38db51ff960ca88b5c396";

        doc = new XmlDocument ();

        var xml = new WebClient().DownloadString(new Uri (weburl));
        doc.LoadXml (xml);
        foreach(XmlNode node in doc.GetElementsByTagName("*"))
        {
             Console.Out.WriteLine(node.Name);
        }

标签: c#gethttp-status-code-404openweathermap

解决方案


推荐阅读