WebRequest 访问 https

参考代码:

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

posted @ 2015-06-27 00:44  Ants  阅读(1675)  评论(0编辑  收藏  举报