forked from Mikou27/Nucleus_Installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HttpClient.cs
36 lines (34 loc) · 1.34 KB
/
HttpClient.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
using System;
using System.IO;
using System.Net;
using System.Windows.Forms;
namespace Updater
{
class HttpClient
{
public string Get(string uri)
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
ServicePointManager.DefaultConnectionLimit = 9999;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.UserAgent = "request";
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (Stream stream = response.GetResponseStream())
using (StreamReader reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
catch (WebException ex)
{
//MessageBox.Show(string.Format("{0}: {1}", ex.ToString(), ex.Message), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("Unable to contact Github.Try again later.", "No valid Github response", MessageBoxButtons.OK, MessageBoxIcon.Information);
return null;
}
}
}
}