1
0
mirror of https://github.com/XFox111/GUTSchedule.git synced 2026-04-22 06:58:01 +03:00
Files
GUTSchedule/GUT.Schedule/GUTSchedule/Extensions.cs
T

30 lines
946 B
C#

using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace GUTSchedule
{
public static class Extensions
{
public static void SetContent(this HttpRequestMessage request, params (string key, string value)[] values)
{
if (request == null)
throw new ArgumentNullException(nameof(request));
Dictionary<string, string> body = new Dictionary<string, string>();
foreach ((string key, string value) in values)
body.Add(key, value);
request.Content = new FormUrlEncodedContent(body);
}
public static async Task<string> GetString(this HttpResponseMessage response)
{
if (response == null)
throw new ArgumentNullException(nameof(response));
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
return Encoding.GetEncoding("Windows-1251").GetString(await response.Content.ReadAsByteArrayAsync().ConfigureAwait(false));
}
}
}