IOException occurs on the HttpWebRequest get https page: authentication fails because the remote party has disabled the transfer stream.

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.