楼主用的是阿里天气免费版,限制1000次,可以重复购买
下面放代码
var orgWindow = new OrganizeWindowProxy(WorkContext); var orgInfo = orgWindow.GetInfoByID(organizeId); var coord = orgInfo.Map.MapList[0]; string lat = "0", lng = "0"; if (coord != null) { lat = coord.Lat; lng = coord.Lnd; } const String host = "http://saweather.market.alicloudapi.com"; const String path = "/gps-to-weather"; const String method = "GET"; const String appcode = "1e37984a57494b14ae6131e760651397"; String querys = string.Format("from=5&lat={0}&lng={1}&need3HourForcast=0&needAlarm=0&needHourData=0&needIndex=0&needMoreDay=0", lat, lng); String bodys = ""; String url = host + path; HttpWebRequest httpRequest = null; HttpWebResponse httpResponse = null; if (0 < querys.Length) { url = url + "?" + querys; } httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Method = method; httpRequest.Headers.Add("Authorization", "APPCODE " + appcode); if (0 < bodys.Length) { byte[] data = Encoding.UTF8.GetBytes(bodys); using (Stream stream = httpRequest.GetRequestStream()) { stream.Write(data, 0, data.Length); } } try { httpResponse = (HttpWebResponse)httpRequest.GetResponse(); } catch (WebException ex) { httpResponse = (HttpWebResponse)ex.Response; } Stream st = httpResponse.GetResponseStream(); StreamReader reader = new StreamReader(st, Encoding.GetEncoding("utf-8")); var weatherJosn = reader.ReadToEnd(); return Json(weatherJosn, JsonRequestBehavior.AllowGet);