When you use HttpWebRequest to request https pages, "IOException: Because the remote party has disabled the transmission stream, authentication fails. ", There are some methods on the Internet, that is, using
C # code
ServicePointManager. ServerCertificateValidationCallback = delegate {return true ;};
It can solve the problem, but sometimes it still cannot be used. You need to add
C # code
ServicePointManager. SecurityProtocol = SecurityProtocolType. Ssl3;
Sets the security protocol used by the ServicePoint object managed by the ServicePointManager object, which is an enumeration value. The following is a complete example.
C # code
String url = "http://www.bkjia.com/kf/201204/127933.html ";
HttpWebRequest myRequest = (HttpWebRequest) WebRequest. Create (url );
MyRequest. Method = "GET ";
MyRequest. Proxy = null;
MyRequest. UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv: 11.0) Gecko/20100101 Firefox/11.0 ";
MyRequest. headers. add ("Accept-Language", "zh-cn, en-us; q = 0.8, zh-hk; q = 0.6, ja; q = 0.4, zh; q = 0.2 ");
MyRequest. Accept = "text/html, application/xhtml + xml, application/xml; q = 0.9, */*; q = 0.8 ";
// ServicePointManager. ServerCertificateValidationCallback = delegate {return true ;}; // This line is useless.
ServicePointManager. SecurityProtocol = SecurityProtocolType. Ssl3;
HttpWebResponse myResponse = (HttpWebResponse) myRequest. GetResponse ();
Response. Write (new System. IO. StreamReader (myResponse. GetResponseStream (), Encoding. GetEncoding ("GB2312"). ReadToEnd ());
Author: Meng xianhui