DutyContent/ThirdParty/WebApi.cs
ksh cbfa535d20
Enhanced after version 14 (#30)
* Add log tab
* Merge control mesg & duty log
* Fix ping (calc loss)
* Add current connection in ping tab. Able to copy by double clicking item
* Log font has moved to config
* Add debug enable on config + save
* Display ping failed reason (debug enable)
* Handled copy exception
* New content list in duty tab
* Show loss rate option in ping tab
* Rename Chinese packet info file (No data)
* Bigger UI font
2021-08-14 23:35:53 +09:00

43 lines
1.1 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)
{
var url = string.Format(urlfmt, args);
try
{
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)
{
Logger.Ex(ex, 30);
Logger.L("URL: {0}", url);
}
return null;
}
}
}