mirror of https://github.com/2dust/v2rayN
DownloadStringAsyncOri
parent
0cdc69e1e8
commit
49fa0a4c67
|
@ -2,6 +2,7 @@
|
|||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Sockets;
|
||||
using v2rayN.Base;
|
||||
using v2rayN.Resx;
|
||||
|
@ -146,6 +147,51 @@ namespace v2rayN.Handler
|
|||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// DownloadString
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
public async Task<string> DownloadStringAsyncOri(string url, bool blProxy, string userAgent)
|
||||
{
|
||||
try
|
||||
{
|
||||
Utils.SetSecurityProtocol(LazyConfig.Instance.GetConfig().enableSecurityProtocolTls13);
|
||||
var client = new HttpClient(new SocketsHttpHandler()
|
||||
{
|
||||
Proxy = GetWebProxy(blProxy)
|
||||
});
|
||||
|
||||
if (Utils.IsNullOrEmpty(userAgent))
|
||||
{
|
||||
userAgent = $"{Utils.GetVersion(false)}";
|
||||
}
|
||||
client.DefaultRequestHeaders.UserAgent.TryParseAdd(userAgent);
|
||||
|
||||
Uri uri = new Uri(url);
|
||||
//Authorization Header
|
||||
if (!Utils.IsNullOrEmpty(uri.UserInfo))
|
||||
{
|
||||
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Utils.Base64Encode(uri.UserInfo));
|
||||
}
|
||||
|
||||
var cts = new CancellationTokenSource();
|
||||
cts.CancelAfter(1000 * 30);
|
||||
|
||||
var result = await HttpClientHelper.GetInstance().GetAsync(client, url, cts.Token);
|
||||
return result;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Utils.SaveLog(ex.Message, ex);
|
||||
Error?.Invoke(this, new ErrorEventArgs(ex));
|
||||
if (ex.InnerException != null)
|
||||
{
|
||||
Error?.Invoke(this, new ErrorEventArgs(ex.InnerException));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int RunAvailabilityCheck(WebProxy webProxy)
|
||||
{
|
||||
try
|
||||
|
|
Loading…
Reference in New Issue