首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

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

2013-09-05 
winfrom 模拟发送post数据登入百度首页winfrom 模拟发送post数据登入百度首页,发现百度采用https协议HttpW

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

热点排行