|
@@ -14,25 +14,23 @@ namespace D3NsCore.Tools
|
|
|
|
|
|
static HttpAccess()
|
|
|
{
|
|
|
- System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
|
|
+ ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
|
|
|
}
|
|
|
|
|
|
- public string GetString(string url, params HttpHeader[] headers)
|
|
|
+ public string GetStringWithoutProxy(string url, params HttpHeader[] headers)
|
|
|
{
|
|
|
- {
|
|
|
- //var client = new HttpClient();
|
|
|
- //client.DefaultRequestHeaders.Add("UserAgent", UserAgent);
|
|
|
- //foreach (var header in headers)
|
|
|
- //{
|
|
|
- // client.DefaultRequestHeaders.Add(header.Name, header.Value);
|
|
|
- //}
|
|
|
- //var str = client.GetStringAsync(url).Result;
|
|
|
- //return str;
|
|
|
- }
|
|
|
+ var wc = new WebClient { Headers = { ["User-Agent"] = UserAgent } };
|
|
|
+ wc.Proxy = new WebProxy();
|
|
|
+ foreach (var header in headers) wc.Headers.Add(header.Name, header.Value);
|
|
|
+ var str = wc.DownloadString(url);
|
|
|
+ return str;
|
|
|
+ }
|
|
|
|
|
|
+ public string GetString(string url, params HttpHeader[] headers)
|
|
|
+ {
|
|
|
var wc = new WebClient { Headers = { ["User-Agent"] = UserAgent } };
|
|
|
wc.Proxy = new WebProxy();
|
|
|
- if (ProxyServer != null) wc.Proxy = new WebProxy(new Uri(ProxyServer));
|
|
|
+ if (string.IsNullOrWhiteSpace(ProxyServer) == false) wc.Proxy = new WebProxy(new Uri(ProxyServer));
|
|
|
foreach (var header in headers) wc.Headers.Add(header.Name, header.Value);
|
|
|
var str = wc.DownloadString(url);
|
|
|
return str;
|
|
@@ -40,20 +38,8 @@ namespace D3NsCore.Tools
|
|
|
|
|
|
public string PutString(string url, string content, string contentType = "application/x-www-form-urlencoded;charset=UTF-8", params HttpHeader[] headers)
|
|
|
{
|
|
|
- {
|
|
|
- //var client = new HttpClient();
|
|
|
- //client.DefaultRequestHeaders.Add("UserAgent", UserAgent);
|
|
|
- //foreach (var header in headers)
|
|
|
- //{
|
|
|
- // client.DefaultRequestHeaders.Add(header.Name, header.Value);
|
|
|
- //}
|
|
|
- //var r = client.PutAsync(url, new StringContent(content, Encoding.UTF8, contentType));
|
|
|
- //var str = r.Result.Content.ReadAsStringAsync().Result;
|
|
|
- //return str;
|
|
|
- }
|
|
|
-
|
|
|
var wc = new WebClient { Headers = { ["User-Agent"] = UserAgent, ["Content-Type"] = contentType } };
|
|
|
- if (ProxyServer != null) wc.Proxy = new WebProxy(new Uri(ProxyServer));
|
|
|
+ if (string.IsNullOrWhiteSpace(ProxyServer)==false) wc.Proxy = new WebProxy(new Uri(ProxyServer));
|
|
|
foreach (var header in headers) wc.Headers.Add(header.Name, header.Value);
|
|
|
|
|
|
try
|