2021-06-10 16:31:15 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using System.Net.Cache;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace DutyContent
|
|
|
|
|
{
|
2021-06-18 14:08:43 +02:00
|
|
|
|
internal static class WebApi
|
|
|
|
|
{
|
|
|
|
|
internal static string Request(string urlfmt, params object[] args)
|
|
|
|
|
{
|
|
|
|
|
var url = string.Format(urlfmt, args);
|
2021-06-10 16:31:15 +02:00
|
|
|
|
|
2021-06-18 14:08:43 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
ServicePointManager.Expect100Continue = true;
|
|
|
|
|
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
|
|
|
|
|
ServicePointManager.DefaultConnectionLimit = 9999;
|
2021-06-10 16:31:15 +02:00
|
|
|
|
|
2021-06-18 14:08:43 +02:00
|
|
|
|
var request = (HttpWebRequest)WebRequest.Create(url);
|
|
|
|
|
request.UserAgent = "DFA";
|
|
|
|
|
request.Timeout = 10000;
|
|
|
|
|
request.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
|
|
|
|
|
using (var response = (HttpWebResponse)request.GetResponse())
|
|
|
|
|
{
|
|
|
|
|
var encoding = Encoding.GetEncoding(response.CharacterSet);
|
2021-06-10 16:31:15 +02:00
|
|
|
|
|
2021-06-18 14:08:43 +02:00
|
|
|
|
using (var responseStream = response.GetResponseStream())
|
|
|
|
|
using (var reader = new StreamReader(responseStream, encoding))
|
|
|
|
|
return reader.ReadToEnd();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
2021-08-14 16:35:53 +02:00
|
|
|
|
Logger.Ex(ex, 30);
|
|
|
|
|
Logger.L("URL: {0}", url);
|
2021-06-18 14:08:43 +02:00
|
|
|
|
}
|
2021-06-10 16:31:15 +02:00
|
|
|
|
|
2021-06-18 14:08:43 +02:00
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-10 16:31:15 +02:00
|
|
|
|
}
|