码迷,mamicode.com
首页 > Web开发 > 详细

WebRequest 访问 https

时间:2015-06-27 01:13:12      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

参考代码:

   1:         [TestMethod]
   2:          public void TestHttps()
   3:          {
   4:              var req =(HttpWebRequest) System.Net.WebRequest.Create("https://www.baidu.com/");
   5:              ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
   6:              var rep =(HttpWebResponse) req.GetResponse();
   7:              var stream = rep.GetResponseStream();
   8:              StreamReader reader = new StreamReader(stream);
   9:              string content = reader.ReadToEnd();
  10:              reader.Close();
  11:              stream.Close();
  12:          }

关键代码:ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

WebRequest 访问 https

标签:

原文地址:http://www.cnblogs.com/leleroyn/p/4603522.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!