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; };
原创文字只代表本人某一时间内的观点或结论,本人不对涉及到的任何代码担保。转载请标明出处!