using Microsoft.Win32; using System; using System.IO; using System.Net.Sockets; namespace Cryville.Common.Network { public class HttpsClient : HttpClient { readonly TlsTcpClient _tlsTcpClient; protected override Stream Stream { get { return _tlsTcpClient.Stream; } } public HttpsClient(Uri baseUri) : base(baseUri, 443) { _tlsTcpClient = new TlsTcpClient(DirectHost, DirectPort); } public override void Connect() { _tlsTcpClient.Connect(); base.Connect(); } public override void Close() { base.Close(); _tlsTcpClient.Close(); } protected override bool GetProxy(ref string host, ref int port) { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { var reg = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings"); var proxyEnable = (int)reg.GetValue("ProxyEnable"); if (proxyEnable == 0) return false; var proxyStr = (string)reg.GetValue("ProxyServer"); if (!string.IsNullOrEmpty(proxyStr)) { string[] proxies = proxyStr.Split(';'); foreach (var p in proxies) { if (p.StartsWith("https=")) { string[] s = p.Split('=', ':'); host = s[1]; port = int.Parse(s[2]); return true; } } } } return false; } } }