none
System.Net.HttpWebRequest does not contain a definition for ServercertificateValidationCallback RRS feed

  • Question

  • I'm trying to compile followed C#-script to dll:

    public partial class CLRTest
    {
         [Microsoft.SqlServer.Server.SqlProcedure]
         public static void TestApi()
         {
              Uri  uri = new Uri("https://test.com/api");
              HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
              request.ServercertificateValidationCallback += Validator;
              ...
         }
    
         public static bool Validator (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
    
         {
              return true;
         }     
    }

    and getting error System.Net.HttpWebRequest does not contain a definition for ServercertificateValidationCallback. How to fix it?

    P.S. I have single script, not project! With console app I had no such error...

    P.P.S. looks like I have to use HttpClient instead HttpWebRequest...
    • Edited by shmonoff Saturday, December 16, 2017 9:22 AM
    Saturday, December 16, 2017 8:40 AM

Answers

  • Try 'ServerCertificateValidationCallback' instead of 'ServercertificateValidationCallback' (it's CamelCase, that means the first letter in the identifier and the first letter of each subsequent word are capitalized).

    wizend

    • Marked as answer by shmonoff Sunday, December 17, 2017 4:55 AM
    Saturday, December 16, 2017 2:05 PM

All replies

  • Try 'ServerCertificateValidationCallback' instead of 'ServercertificateValidationCallback' (it's CamelCase, that means the first letter in the identifier and the first letter of each subsequent word are capitalized).

    wizend

    • Marked as answer by shmonoff Sunday, December 17, 2017 4:55 AM
    Saturday, December 16, 2017 2:05 PM
  • Solved with ServicePointManager, because HttpWebRequest inherits property ServerCertificateValidationCallback from it.
    Sunday, December 17, 2017 4:22 AM
  • just checked, you are right, that is reason of problem. thank you!
    Sunday, December 17, 2017 4:55 AM