Example #1
0
            static Uri GetProxyUri(CFProxy proxy)
            {
                string protocol;

                switch (proxy.ProxyType)
                {
                case CFProxyType.FTP:
                    protocol = "ftp://";
                    break;

                case CFProxyType.HTTP:
                    protocol = "http://";
                    break;

                case CFProxyType.HTTPS:
                    protocol = "https://";
                    break;

                default:
                    return(null);
                }

                string username = proxy.Username;
                string password = proxy.Password;
                string hostname = proxy.HostName;
                int    port     = proxy.Port;
                string userinfo;
                string uri;

                if (username != null)
                {
                    if (password != null)
                    {
                        userinfo = Uri.EscapeDataString(username) + ':' + Uri.EscapeDataString(password) + '@';
                    }
                    else
                    {
                        userinfo = Uri.EscapeDataString(username) + '@';
                    }
                }
                else
                {
                    userinfo = string.Empty;
                }

                uri = protocol + userinfo + hostname + (port != 0 ? ':' + port.ToString() : string.Empty);

                return(new Uri(uri, UriKind.Absolute));
            }
Example #2
0
            static Uri GetProxyUri(CFProxy proxy, out NetworkCredential credentials)
            {
                string protocol;

                switch (proxy.ProxyType)
                {
                case CFProxyType.FTP:
                    protocol = "ftp://";
                    break;

                case CFProxyType.HTTP:
                case CFProxyType.HTTPS:
                    protocol = "http://";
                    break;

                default:
                    credentials = null;
                    return(null);
                }

                string username = proxy.Username;
                string password = proxy.Password;
                string hostname = proxy.HostName;
                int    port     = proxy.Port;
                string uri;

                if (username != null)
                {
                    credentials = new NetworkCredential(username, password);
                }
                else
                {
                    credentials = null;
                }

                uri = protocol + hostname + (port != 0 ? ':' + port.ToString() : string.Empty);

                return(new Uri(uri, UriKind.Absolute));
            }