|
| 1 | +using System; |
| 2 | +using System.IO; |
| 3 | +using System.Net; |
| 4 | +using System.Text; |
| 5 | +using System.Threading.Tasks; |
| 6 | + |
| 7 | +namespace NTMiner { |
| 8 | + public static class HtmlUtil { |
| 9 | + public static async Task<string> GetF2poolHtmlAsync() { |
| 10 | + return await Task.Factory.StartNew(() => { |
| 11 | + try { |
| 12 | + string url = $"https://www.f2pool.com/?t={DateTime.Now.Ticks.ToString()}"; |
| 13 | + if (url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)) { |
| 14 | + // 没有这一行可能会报错:System.Net.WebException: 请求被中止: 未能创建 SSL/TLS 安全通道 |
| 15 | + ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; |
| 16 | + } |
| 17 | + var httpWebRequest = WebRequest.Create(url) as HttpWebRequest; |
| 18 | + httpWebRequest.Timeout = 30 * 1000; |
| 19 | + httpWebRequest.Method = "GET"; |
| 20 | + httpWebRequest.Referer= "http://dl.ntminer.top"; |
| 21 | + httpWebRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9"; |
| 22 | + httpWebRequest.Headers["accept-encoding"] = "gzip, deflate, br"; |
| 23 | + httpWebRequest.Headers["accept-language"] = "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6"; |
| 24 | + httpWebRequest.Headers["cache-control"] = "max-age=0"; |
| 25 | + httpWebRequest.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.67"; |
| 26 | + var response = httpWebRequest.GetResponse(); |
| 27 | + using (Stream ms = new MemoryStream(), stream = response.GetResponseStream()) { |
| 28 | + byte[] buffer = new byte[NTKeyword.IntK]; |
| 29 | + int n = stream.Read(buffer, 0, buffer.Length); |
| 30 | + while (n > 0) { |
| 31 | + ms.Write(buffer, 0, n); |
| 32 | + n = stream.Read(buffer, 0, buffer.Length); |
| 33 | + } |
| 34 | + byte[] data = new byte[ms.Length]; |
| 35 | + ms.Position = 0; |
| 36 | + ms.Read(data, 0, data.Length); |
| 37 | + data = RpcRoot.ZipDecompress(data); |
| 38 | + return Encoding.UTF8.GetString(data); |
| 39 | + } |
| 40 | + } |
| 41 | + catch (Exception e) { |
| 42 | + Logger.ErrorDebugLine(e); |
| 43 | + return string.Empty; |
| 44 | + } |
| 45 | + }); |
| 46 | + } |
| 47 | + } |
| 48 | +} |
0 commit comments