带有 https 的 C# WebClient [英] C# WebClient with https
问题描述
我想使用 https 使用 WebClient 的 UploadData 方法上传文件.而且我想忽略服务器端证书验证(始终接受服务器证书并且只使用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?
我使用的是 VSTS2008 + C# + .Net 3.5.目标服务器运行 IIS 7.0 + Windows Vista x64.
I am using VSTS2008 + C# + .Net 3.5. Target server is running with IIS 7.0 + Windows Vista x64.
推荐答案
在向您发送 HTTPS 请求之前尝试添加此内容(确保导入 System.Net
命名空间).
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;
};
这篇关于带有 https 的 C# WebClient的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!