forked from MatheusGrijo/ArbitragemNacionalV2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Http.cs
52 lines (45 loc) · 1.47 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
51
52
using System;
using System.IO;
using System.Net;
using System.Text;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Net.Security;
public static class Http
{
static string ByteToString(byte[] buff)
{
string sbinary = "";
for (int i = 0; i < buff.Length; i++)
{
sbinary += buff[i].ToString("X2"); /* hex format */
}
return (sbinary);
}
public static readonly Object objLock = new object();
public static readonly Object objLock2 = new object();
public static string get(String url)
{
try
{
String r = "";
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var httpWebRequest = (HttpWebRequest)WebRequest.Create(new Uri(url));
httpWebRequest.Method = "GET";
var httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
var responseStream = httpWebResponse.GetResponseStream();
if (responseStream != null)
{
var streamReader = new StreamReader(responseStream);
r = streamReader.ReadToEnd();
}
if (responseStream != null) responseStream.Close();
return r;
}
catch (WebException ex)
{
return null;
}
}
}