WCF per connection server certificate validation

前端 未结 7 3488
清歌不尽
清歌不尽 2021-02-20 13:50

I\'m trying to bypass https certificate validation only to our own testing environment (multiple machines), while trying to keep certificate validation for all the other connect

7条回答
  •  轮回少年
    2021-02-20 13:57

    Seems like in .NET 4.5 you can do the following:

    var request = (HttpWebRequest)WebRequest.Create(url);
    request.ServerCertificateValidationCallback += 
        (sender, certificate, chain, sslPolicyErrors) => true
    

    I did not realize it initially, as you actually have to cast result of Create method to HttpWebRequest, as abstract WebRequest does not contain this delegate.

提交回复
热议问题