コード例 #1
0
        private async void connectProxyAsync(IProxy proxy, string user, string password)
        {
            try {
                Uri destinationUri = new Uri("http://" + _logic.UrlRequest.Host + ":" + _logic.UrlRequest.Port);
                var proxyServer    = await proxy.CreateProxyAsync(destinationUri);

                if (proxyServer == null)
                {
                    OpenConnectionToRemote();
                    return;
                }

                _logic.HasProxy = true;
                //create remote endpoint
                IPAddress add = IPAddress.Parse(proxyServer.Address.Host);
                //connect remote proxy endpoint
                await _client.ConnectAsync(add, proxyServer.Address.Port).ConfigureAwait(false);

                NetworkStream = _client.GetStream();
                var proxyRequest = _logic.ProxyRequest();
                NetworkStream.Write(proxyRequest, 0, proxyRequest.Length);
                await WaitForResponse(NetworkStream).ConfigureAwait(false);
            } catch (Exception E) {
                Console.WriteLine(E.Message);
            }
        }