Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# WebClient with https

I want to use https to upload a file using WebClient's UploadData method. And I want to ignore server side certificate verification (always accept server certificate and only use encryption feature of https).

I have tried hard but cannot find a similar sample. Could anyone advise me how to implement? Any reference samples?

I am using VSTS2008 + C# + .Net 3.5. Target server is running with IIS 7.0 + Windows Vista x64.

like image 742
George2 Avatar asked Aug 27 '09 06:08

George2


1 Answers

Try adding this before you send you HTTPS requests (make sure you import System.Net namespace).

ServicePointManager.ServerCertificateValidationCallback += 
    delegate(object sender, X509Certificate certificate, X509Chain chain, 
    SslPolicyErrors sslPolicyErrors)
{
   return true;
};
like image 103
RaYell Avatar answered Sep 21 '22 05:09

RaYell