-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHttp.cs
50 lines (43 loc) · 1.41 KB
/
Http.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Net;
using System.Threading.Tasks;
namespace WebLib
{
public static class Http
{
public static HttpResponse SendRequest(string url, HttpRequest options)
{
return SendRequestAsync(url, options).GetAwaiter().GetResult();
}
public static Task<HttpResponse> SendRequestAsync(string url, HttpRequest options)
{
options.Url = url;
return SendRequestAsync(options);
}
public static HttpResponse SendRequest(HttpRequest options)
{
return SendRequestAsync(options).GetAwaiter().GetResult();
}
public static Task<HttpResponse> SendRequestAsync(HttpRequest options)
{
return SendRequestAsync(options.GetHttpWebRequest());
}
public static HttpResponse SendRequest(HttpWebRequest request)
{
return SendRequestAsync(request).GetAwaiter().GetResult();
}
public async static Task<HttpResponse> SendRequestAsync(HttpWebRequest request)
{
HttpResponse response;
try
{
response = new HttpResponse((HttpWebResponse)await request.GetResponseAsync());
}
catch (WebException ex)
{
response = new HttpResponse((HttpWebResponse)ex.Response, true, ex);
}
return response;
}
}
}