.NET HttpWebRequest HTTPS Error

荒凉一梦 提交于 2019-12-11 04:46:23

问题


Hello I'm trying to fetch data from a https web (i'm not behind firewall or proxy) however even accepting all certificates it keeps throwing System.Net.WebExceptionStatus.SecureChannelFailure with the message shown: Cancelled the request: Unable to create a secure SSL/TLS channel ... i've looked everywhere so you guys are my last chance.

   static void Main(string[] args)
            {
                RemoteCertificateValidationCallback ServerCertificateValidationCallback = delegate { return true; };
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://miyoigo.yoigo.com");
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                {
                    Console.Write(reader.ReadToEnd());
                }
            }

Thanks in advance ;)


回答1:


try printing the InnerException property of the WebException, should provide a particular reason the negot failed

Console.WriteLine("Inner Exception");
Console.WriteLine(String.Concat(e.InnerException.StackTrace, e.InnerException.Message));



回答2:


That code works fine for me exactly as you have it. My guess is that you've got something network related going on. Are you behind a proxy or firewall? Like Ray said in his comment, try hitting that URL from a browser.




回答3:


I have resolved my problem looking at: How do you get a System.Web.HttpWebRequest object to use SSL 2.0?



来源:https://stackoverflow.com/questions/2078682/net-httpwebrequest-https-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!