-1

I Am trying to make a request to server, but however my server is setup with custom ssl openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes however how can I set to false verification ssl similar to python requests.get(url,verify=false)

client

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
    using (Stream stream = response.GetResponseStream())
    {
        using (StreamReader reader = new StreamReader(stream))
        {
            html = reader.ReadToEnd();
            Console.WriteLine(html);
        }
    }
}
Masoud Keshavarz
  • 2,166
  • 9
  • 36
  • 48
Store LTE
  • 11
  • 6
  • You can add some logic instead skipping all validation. You may want to check the validation error and ignore it only if it is cert expired but raise other errors – Cleptus Aug 14 '19 at 06:15

1 Answers1

6

You can add the following to your code:

request.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

So the endresult would be:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

request.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;

using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        html = reader.ReadToEnd();
                        Console.WriteLine(html);
                    }
                }
            }
Zoltan David
  • 221
  • 1
  • 2