Пример #1
0
        public static void UpdateUpStreamProxy()
        {
            string proxy = AppConfig.m_config.ProxyIP + ":" + AppConfig.m_config.ProxyPort;


            if (Regex.IsMatch(proxy, @"^\d+$")) //只输入了端口 则补充完全
            {
                proxy = "127.0.0.1:" + proxy;
            }

            if (string.IsNullOrWhiteSpace(AppConfig.m_config.ProxyIP) || string.IsNullOrWhiteSpace(proxy))
            {
                proxyServer.UpStreamHttpProxy = null;
            }
            else
            {
                string[] proxys = proxy.Split(":".ToCharArray());
                if (proxys.Length != 2)
                {
                    EasyLog.Write("错误的代理设置");
                }
                else
                {
                    EasyLog.Write($"更新代理地址:{proxys[0]}:{proxys[1]}");

                    proxyServer.UpStreamHttpProxy = new ExternalProxy
                    {
                        HostName = proxys[0],
                        Port     = int.Parse(proxys[1]),
                    };
                }
            }
        }
Пример #2
0
        public static void Init()
        {
            proxyServer = new ProxyServer(false);
            proxyServer.ForwardToUpstreamGateway = true;

            //proxyServer.BeforeRequest += OnRequest;
            //proxyServer.BeforeResponse += OnResponse;
            //proxyServer.ServerCertificateValidationCallback += OnCertificateValidation;
            //proxyServer.ClientCertificateSelectionCallback += OnCertificateSelection;

            UpdateUpStreamProxy();
            localProxyProt = GetCanUsePort();
            EasyLog.Write("HttpProxyStart:" + localProxyProt);
            var endPoint = new ExplicitProxyEndPoint(IPAddress.Parse("127.0.0.1"), localProxyProt, false);

            proxyServer.AddEndPoint(endPoint);
            proxyServer.Start();
        }