From 49fa0a4c673e1f5a9a818e10d4eec9f997a89778 Mon Sep 17 00:00:00 2001
From: 2dust <31833384+2dust@users.noreply.github.com>
Date: Fri, 10 Feb 2023 11:04:57 +0800
Subject: [PATCH] DownloadStringAsyncOri
---
v2rayN/v2rayN/Handler/DownloadHandle.cs | 46 +++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/v2rayN/v2rayN/Handler/DownloadHandle.cs b/v2rayN/v2rayN/Handler/DownloadHandle.cs
index 8ebb1fae..29e2b10d 100644
--- a/v2rayN/v2rayN/Handler/DownloadHandle.cs
+++ b/v2rayN/v2rayN/Handler/DownloadHandle.cs
@@ -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;
}
+ ///
+ /// DownloadString
+ ///
+ ///
+ public async Task 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