简体   繁体   English

使用https的C#WebClient

[英]C# WebClient with https

I want to use https to upload a file using WebClient's UploadData method. 我想使用https来使用WebClient的UploadData方法上传文件。 And I want to ignore server side certificate verification (always accept server certificate and only use encryption feature of https). 我想忽略服务器端证书验证(始终接受服务器证书并且仅使用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. 我使用的是VSTS2008 + C#+ .Net 3.5。 Target server is running with IIS 7.0 + Windows Vista x64. 目标服务器与IIS 7.0 + Windows Vista x64一起运行。

Try adding this before you send you HTTPS requests (make sure you import System.Net namespace). 在向您发送HTTPS请求之前尝试添加此项(确保导入System.Net命名空间)。

ServicePointManager.ServerCertificateValidationCallback += 
    delegate(object sender, X509Certificate certificate, X509Chain chain, 
    SslPolicyErrors sslPolicyErrors)
{
   return true;
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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