读书人

winfrom 模拟发送post数据登进百度首页

发布时间: 2013-09-05 16:02:07 作者: rapoo

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);

读书人网 >C#

热点推荐