Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpWebRequest over SSL?

I've used HttpWebRequests to post data to HTTPS websites before, and I've never had todo anything different than a regular HTTP Post.

Does anyone know if there are any tricks involved that I missed to ensure that this is done properly?

like image 242
FlySwat Avatar asked May 08 '26 17:05

FlySwat


2 Answers

After a little searching, it looks like you don't have to do anything if the certificate is valid.

If you want to examine the certificate yourself, you can do this:

System.Net.ServicePointManager.ServerCertificateValidationCallback +=
    delegate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
                            System.Security.Cryptography.X509Certificates.X509Chain chain,
                            System.Net.Security.SslPolicyErrors sslPolicyErrors)
        {
            return true; // **** Always accept
        };

The above code came from a comment on Rick Stralhs blog, and will force always accepting the client cert.

You can also validate the cert there in that delegate.

Cool stuff!

like image 150
FlySwat Avatar answered May 11 '26 15:05

FlySwat


Check for certification errors, this i a common issue http://www.west-wind.com/weblog/posts/48909.aspx

like image 39
Oscar Cabrero Avatar answered May 11 '26 14:05

Oscar Cabrero



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!