简体   繁体   中英

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.

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;
};

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM