想通过HttpWebRequest向带有https的网站发送模拟登录信息时出来的提示:基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系。请问是什么原因造成的?如何解决?

解决方案 »

  1.   

    http://www.cnblogs.com/zhongzf/archive/2006/10/27/386902.html
      

  2.   


    internal class AcceptAllCertificatePolicy : ICertificatePolicy
            {
                public AcceptAllCertificatePolicy()
                {
                }            public bool CheckValidationResult(ServicePoint sPoint, X509Certificate cert, WebRequest wRequest, int certProb)
                {
                    return true;
                }
            }private void SendData(){ HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL);              string postData = "operatoraccount=admin" ;
                  postData += "&operatorpwd=portal";
                myRequest.ContentType = "application/x-www-form-urlencoded";
                myRequest.KeepAlive = true;
                ServicePointManager.CertificatePolicy = new AcceptAllCertificatePolicy();
                
                MessageBox.Show(GetResponse (myRequest ,postData));} private  string  GetResponse(HttpWebRequest webRequest, string request)
            {
                byte[] requestBytes = Encoding.ASCII.GetBytes(request);
                webRequest.ContentLength = requestBytes.Length;
                webRequest.Method = "POST";
                //   Write   the   request   
                Stream reqStream = webRequest.GetRequestStream();
                reqStream.Write(requestBytes, 0, requestBytes.Length);
                reqStream.Close();
                //   Get   a   response   
                HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
                
                if (webRequest.HaveResponse)
                {
                    //   Read   response   
                    //StreamReader oStream = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.ASCII);                StreamReader oStream = new StreamReader(webResponse.GetResponseStream(), Encoding.Default);
                    string content = oStream.ReadToEnd();
                    oStream.Close();
                    webResponse.Close();                return content;            }
                return "";
            } 
      

  3.   

    To blestcc
    不能用啊,你试试 http://esales.sdo.com
      

  4.   

    错误 3 “CheckValidationResult”的重载均与委托“System.Net.Security.RemoteCertificateValidationCallback”不匹配
    这个是什么意思呢??ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
      

  5.   

    using System.Security.Cryptography.X509Certificates;
    我用2003測試正常
      

  6.   

    你好,可否把程序发给我一下呢?谢谢  [email protected]
      

  7.   

    收到了你的邮件,可HOTMAIL不给我下载文件......能否再重新发一次?改下扩展名好吗?谢谢
      

  8.   

    很好,正为ssl烦恼,学习了,实践了,成功了,谢谢啦!
      

  9.   

    看来前辈们都遇见这个问题了,我今天也遇见这个问题 了,我在做天堂的时候,用ie打开提示证书错误,然后用httpwebrequest的时候也是提示:基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系。我改怎么办呢?