关于访问Https网站的问题

diqiuproj 2008-12-26 12:07:09
我要访问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协议过程来看有没有什么问题?
...全文
155 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
diqiuproj 2008-12-26
  • 打赏
  • 举报
回复
没人懂吗?

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧