Esempio n. 1
0
        /// <summary>
        /// Invokes <c>InternetConnect</c>, handling error conditions.
        /// </summary>
        /// <param name="internet">The parent opened internet handle.</param>
        /// <param name="serverName">Name of the server to which to connect.</param>
        /// <param name="serverPort">The server port to which to connect.</param>
        /// <param name="username">The username to use for authentication.</param>
        /// <param name="password">The password to use for authentication.</param>
        /// <param name="service">The service type to which to connect.</param>
        /// <param name="flags">The connection flags.</param>
        /// <returns>The connected internet handle.</returns>
        public static SafeInternetHandle InternetConnect(SafeInternetHandle internet, string serverName, ushort serverPort, string username, string password, InternetConnectHandle.Service service, InternetConnectHandle.Flags flags)
        {
            SafeInternetHandle ret = DoInternetConnect(internet, serverName, serverPort, username, password, service, flags, (IntPtr)1);

            if (ret.IsInvalid)
            {
                throw GetLastInternetException();
            }

            return(ret);
        }
Esempio n. 2
0
 private static extern SafeInternetHandle DoInternetConnect(SafeInternetHandle hInternet, string lpszServerName, ushort nServerPort, string lpszUserName, string lpszPassword, InternetConnectHandle.Service dwService, InternetConnectHandle.Flags dwFlags, IntPtr dwContext);
        /// <summary>
        /// Establishes a connection to the specified server.
        /// </summary>
        /// <param name="serverName">Name of the server to which to connect.</param>
        /// <param name="serverPort">The server port to which to connect.</param>
        /// <param name="username">The username to use for authentication.</param>
        /// <param name="password">The password to use for authentication.</param>
        /// <param name="service">The service type to which to connect.</param>
        /// <param name="flags">The connection flags.</param>
        /// <returns>An established internet connection to the specified server.</returns>
        public InternetConnectHandle Connect(string serverName, int serverPort, string username, string password, InternetConnectHandle.Service service, InternetConnectHandle.Flags flags)
        {
            switch (service)
            {
            case InternetConnectHandle.Service.Ftp:
                return(new FtpHandle(this, serverName, serverPort, username, password, flags));

            case InternetConnectHandle.Service.Gopher:
            case InternetConnectHandle.Service.Http:
            default:
                return(new InternetConnectHandle(this, serverName, serverPort, username, password, service, flags));
            }
        }