关于访问Https网站的问题
我要访问https的网站不需要客户端证书,我的关键代码如下:
HttpWebRequest hwq = (HttpWebRequest)WebRequest.Create(loginurl);
hwq.ContentType = "text/html";
string pstr = "posted=yes";
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(pstr);
hwq.ContentLength = bytes.Length;
hwq.Method = "POST";
hwq.Headers["UserAgent"] = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727; Alexa Toolbar; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
Stream newStream = hwq.GetRequestStream();
newStream.Write(bytes, 0, bytes.Length);
newStream.Flush();
newStream.Close();
HttpWebResponse hwr = (HttpWebResponse)hwq.GetResponse();
Stream s = hwr.GetResponseStream();
服务器返回的结果也没有提示出错,http的code 也是OK。
但是返回的HTML代码不是满意的答案,也就是和用浏览器访问的结果不一样。不知道我上面的代码从https协议过程来看有没有什么问题?