Ejemplo n.º 1
0
        /// <summary>
        /// Fetches a web page under SSL using POST
        /// </summary>
        /// <param name="uri">The URL.</param>
        /// <param name="userName">The user name</param>
        /// <param name="password">The password</param>
        /// <returns>A string with the content of the web page</returns>
        /// <exception cref="ArgumentNullException"><c>userName</c> is null.</exception>
        public static string PostSecureWebPage(Uri uri, string userName, string password)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }
            if (String.IsNullOrEmpty(userName))
            {
                throw new ArgumentNullException("userName");
            }
            if (String.IsNullOrEmpty(password))
            {
                throw new ArgumentNullException("password");
            }
            var overrride = new CertificateOverride();

            ServicePointManager.ServerCertificateValidationCallback = overrride.RemoteCertificateValidationCallback;
            var request = (HttpWebRequest)WebRequest.Create(uri);

            request.Method      = WebRequestMethods.Http.Post;
            request.ContentType = "application/x-www-form-urlencoded";
            request.Credentials = new NetworkCredential(userName, password);

            var stream  = request.GetResponse().GetResponseStream();
            var sr      = new StreamReader(stream);
            var webPage = sr.ReadToEnd();

            sr.Close();

            return(webPage);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Fetches a web page under SSL using GET
        /// </summary>
        /// <param name="uri">The URL.</param>
        /// <param name="userName">The user name</param>
        /// <param name="password">The password</param>
        /// <returns>A string with the content of the web page</returns>
        public static string GetSecureWebPage(Uri uri, string userName, string password)
        {
            var overrride = new CertificateOverride();
            ServicePointManager.ServerCertificateValidationCallback = overrride.RemoteCertificateValidationCallback;
                //new TrustAllCertificatePolicy();

            var request = (HttpWebRequest) WebRequest.Create(uri);
            request.Credentials = new NetworkCredential(userName, password);

            Stream stream = request.GetResponse().GetResponseStream();
            var sr = new StreamReader(stream);
            string webPage = sr.ReadToEnd();
            sr.Close();

            return webPage;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Fetches a web page under SSL using GET
        /// </summary>
        /// <param name="uri">The URL.</param>
        /// <param name="userName">The user name</param>
        /// <param name="password">The password</param>
        /// <returns>A string with the content of the web page</returns>
        public static string GetSecureWebPage(Uri uri, string userName, string password)
        {
            var overrride = new CertificateOverride();

            ServicePointManager.ServerCertificateValidationCallback = overrride.RemoteCertificateValidationCallback;
            //new TrustAllCertificatePolicy();

            var request = (HttpWebRequest)WebRequest.Create(uri);

            request.Credentials = new NetworkCredential(userName, password);

            Stream stream  = request.GetResponse().GetResponseStream();
            var    sr      = new StreamReader(stream);
            string webPage = sr.ReadToEnd();

            sr.Close();

            return(webPage);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Fetches a web page under SSL using POST
        /// </summary>
        /// <param name="uri">The URL.</param>
        /// <param name="userName">The user name</param>
        /// <param name="password">The password</param> 
        /// <returns>A string with the content of the web page</returns>
        /// <exception cref="ArgumentNullException"><c>userName</c> is null.</exception>
        public static string PostSecureWebPage(Uri uri, string userName, string password)
        {
            if (uri == null) throw new ArgumentNullException("uri");
            if (String.IsNullOrEmpty(userName)) throw new ArgumentNullException("userName");
            if (String.IsNullOrEmpty(password)) throw new ArgumentNullException("password");
            var overrride = new CertificateOverride();
            ServicePointManager.ServerCertificateValidationCallback = overrride.RemoteCertificateValidationCallback;
            var request = (HttpWebRequest) WebRequest.Create(uri);
            request.Method = WebRequestMethods.Http.Post;
            request.ContentType = "application/x-www-form-urlencoded";
            request.Credentials = new NetworkCredential(userName, password);

            var stream = request.GetResponse().GetResponseStream();
            var sr = new StreamReader(stream);
            var webPage = sr.ReadToEnd();
            sr.Close();

            return webPage;
        }