forked from LingFeng-bbben/MajdataEdit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebControl.cs
44 lines (36 loc) · 1.24 KB
/
WebControl.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
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Text;
namespace MajdataEdit;
internal static class WebControl
{
public static string RequestPOST(string url, string data = "")
{
try
{
using var client = new HttpClient();
var webRequest = new HttpRequestMessage(HttpMethod.Post, url)
{
Content = new StringContent(data, Encoding.UTF8)
};
var response = client.Send(webRequest);
using var reader = new StreamReader(response.Content.ReadAsStream());
return reader.ReadToEnd();
}
catch
{
return "ERROR";
}
}
public static string RequestGETAsync(string url)
{
var executingAssembly = Assembly.GetExecutingAssembly();
using var httpClient = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Add("User-Agent", $"{executingAssembly.GetName().Name!} / {executingAssembly.GetName().Version!.ToString(3)}");
var response = httpClient.Send(request);
using var reader = new StreamReader(response.Content.ReadAsStream());
return reader.ReadToEnd();
}
}