5228a2eb6c
* add an updator * change update branch * make updater work * change update branch * make work * add new line * add exception log + clean up
42 lines
1.3 KiB
C#
42 lines
1.3 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Net.Cache;
|
|
using System.Text;
|
|
|
|
namespace DutyContent
|
|
{
|
|
internal static class WebApi
|
|
{
|
|
internal static string Request(string urlfmt, params object[] args)
|
|
{
|
|
try
|
|
{
|
|
var url = string.Format(urlfmt, args);
|
|
|
|
ServicePointManager.Expect100Continue = true;
|
|
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
|
|
ServicePointManager.DefaultConnectionLimit = 9999;
|
|
|
|
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);
|
|
|
|
using (var responseStream = response.GetResponseStream())
|
|
using (var reader = new StreamReader(responseStream, encoding))
|
|
return reader.ReadToEnd();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MesgLog.Ex(ex, 30);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|
|
}
|