日期:2014-05-17  浏览次数:20907 次

winfrom 模拟发送post数据登入百度首页
winfrom 模拟发送post数据登入百度首页,发现百度采用https协议
  
            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://passport.baidu.com/?login");
            myRequest.Method = "POST";
            myRequest.ContentType = "application/x-www-form-urlencoded";
            myRequest.ContentLength = data.Length;
            Stream newStream = myRequest.GetRequestStream();
            // Send the data.
            newStream.Write(data, 0, data.Length);
            newStream.Close();
            // Get response
            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();

提示  基础连接已经关闭: 接收时发生错误。

应该如何解决?

------解决方案--------------------

public bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{
    return true;
}

//HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://passport.baidu.com/?login");之前加入
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);