mercredi 1 juillet 2015

Access to https site from c#

I need to download some files from a HTTPS site but I am having some troubles trying to access the site. This is the code I am trying to use:

            HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("https://website/");
            req.CookieContainer = new CookieContainer();       
            req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705;)";
            req.Method = "POST";
            req.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            req.Headers.Add("Accept-Language: en-us,en;q=0.5");
            req.Headers.Add("Accept-Encoding: gzip,deflate");
            req.Headers.Add("Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7");
            req.KeepAlive = true;
            req.Headers.Add("Keep-Alive: 300");
            req.Referer = "https://website.com/";

            req.ContentType = "application/x-www-form-urlencoded";

            String Username = "userxxxxxx";
            String PassWord = "passxxxxxx";

            StreamWriter sw = new StreamWriter(req.GetRequestStream());
            sw.Write("http://ift.tt/1C9K2tK" + Username + "&login_password=" + PassWord);
            sw.Close();

            HttpWebResponse response = (HttpWebResponse)req.GetResponse();

I always get the error:

The Underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

Any advice or suggestions

Thanks in advance




Aucun commentaire:

Enregistrer un commentaire