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
}