C#Web客户端以https [英] C# WebClient with https

查看:164
本文介绍了C#Web客户端以https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用https上传使用Web客户端的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的64位。

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

这篇关于C#Web客户端以https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆