private async Task PostWeibo(Weather weather) { string token = "2.005MlWeH0GByfS2b6ddd6bb9jLrEeC"; string status = $"时间:{weather.DateTime.ToString("yyyy/MM/dd HH:mm")}%0a" + $"温度:{Math.Round(weather.Temperature, 1)} ℃%0a" + $"相对湿度:{Math.Round(weather.Humidity)} %25%0a" + $"气压:{Math.Round(weather.Pressure)} Pa%0a" + $"可吸入颗粒物:{weather.Dust} mg%2fm3%0a" + $"http://maestrobot.cn"; var hoursData = _context.Select6HourData(); using (HttpClient client = new HttpClient()) { Svg2Png(GetTempModel(hoursData)); var pngStream = System.IO.File.OpenRead("img.png"); MultipartFormDataContent content = new MultipartFormDataContent { { new StringContent(token, Encoding.UTF8), "access_token" }, { new StringContent(status, Encoding.UTF8), "status" }, { new StreamContent(pngStream, (int)pngStream.Length), "pic", "img.png" } }; HttpResponseMessage response = await client.PostAsync("https://api.weibo.com/2/statuses/share.json", content); var s = await content.ReadAsStringAsync(); var str = await response.Content.ReadAsStringAsync(); pngStream.Dispose(); } }
public IActionResult Index() { // Select Latest Data ViewData["LatestData"] = _context.Weathers.OrderByDescending(x => x.DateTime) .First(); // Select 6 Hour Data ViewData["HoursData"] = _context.Select6HourData(); return(View()); }