C #. VB. NET using httpwebrequest to access the HTTPS address (SSL)

Source: Internet
Author: User

When you use httpwebrequest to access an SSL address https: // xxxx, error "failed to establish trust relationship for SSL/TLS Security Channel (cocould not establish trust relationship for the SSL/TLS Secure Channel )"

 

 

 

I checked msdn and found a solution. For SSL websites, certificates must be provided during connection. If client certificates are not requiredReturns a security confirmation.You can. However, the implementation of this method is different in. NET 1.1 and. NET 2.0.

Namespace used:

 Using  System  .  Net  ;  Using  System  .  Net  .  Security ;  Using  System  .  Security  .  Authentication  ;  Using  System  .  Security  .  Cryptography  .  X509certificates  ; 

. NET 2.0

Public  Bool  Checkvalidationresult  (  Object  Sender  ,  X509certificate Certificate  ,  X509chain chain  ,  Sslpolicyerrors errors  ){  // Directly confirm, otherwise it cannot be opened  Return  True  ;} Private void  Button#click  (  Object  Sender  ,  Eventargs  E  ){      Servicepointmanager  .  Servercertificatevalidationcallback  =  New  System  .  Net  .  Security  .  Remotecertificatevalidationcallback  (  Checkvalidationresult  );      Httpwebrequest  REQ  = ( Httpwebrequest  )  Webrequest  .  Createdefault  (  New  Uri  (  "Https://zu14.cn /"  ));      REQ  .  Method  =  "Get"  ;      Httpwebresponse  Res  = (  Httpwebresponse  )  REQ  .  Getresponse  ();      //... Normal use, and access common http:  // The address is the same  

}

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.