Пример #1
0
        private async static Task PostWeiboAsync(Weather weather)
        {
            string token  = ConfigHelper.Get("Weibo:Token"); // weibo token
            string status = $"{weather.DateTime.ToString("yyyy/MM/dd HH:mm")}    {weather.WeatherName}%0a" +
                            $"温度:{Math.Round(weather.Temperature, 1)} ℃    体感温度:{Math.Round(WeatherHelper.CalHeatIndex(weather.Temperature, weather.Humidity), 1)} ℃%0a" +
                            $"相对湿度:{Math.Round(weather.Humidity)} %25%0a" +
                            $"气压:{Math.Round(weather.Pressure / 100, 2)} hPa%0a" +
                            $"{ConfigHelper.Get("Weibo:StatusUrl")}";

            using HttpClient client      = new HttpClient();
            using FileStream imageStream = File.OpenRead(ConfigHelper.Get("UsbCamera:ImagePath"));

            MultipartFormDataContent content = new MultipartFormDataContent
            {
                { new StringContent(token, Encoding.UTF8), "access_token" },
                { new StringContent(status, Encoding.UTF8), "status" },
                { new StreamContent(imageStream, (int)imageStream.Length), "pic", "image.jpg" }
            };

            HttpResponseMessage response = await client.PostAsync("https://api.weibo.com/2/statuses/share.json", content);
        }