-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHttpClientFactory.cs
More file actions
40 lines (35 loc) · 1.28 KB
/
HttpClientFactory.cs
File metadata and controls
40 lines (35 loc) · 1.28 KB
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
using System;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
namespace STGCLauncher
{
public static class HttpClientFactory
{
public static HttpClient Create()
{
var handler = new HttpClientHandler
{
ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true,
AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate,
UseCookies = false,
AllowAutoRedirect = true,
MaxAutomaticRedirections = 3
};
var client = new HttpClient(handler)
{
Timeout = TimeSpan.FromSeconds(30)
};
client.DefaultRequestHeaders.UserAgent.ParseAdd(
"STGCLauncher/1.0 (Windows NT 10.0; Win64; x64)");
client.DefaultRequestHeaders.Accept.ParseAdd("text/plain,text/html,*/*");
client.DefaultRequestHeaders.AcceptEncoding.ParseAdd("gzip, deflate");
client.DefaultRequestHeaders.Connection.ParseAdd("keep-alive");
client.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue
{
NoCache = true
};
return client;
}
}
}