C# WebClient 下载字符串 https [英] C# WebClient Download String https

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

问题描述

在网页浏览器中,我通常可以加载以下网址:https://security.ultimatxxxx.com:443/Serverstatus.ashx

In the webbrowser I can normally load the following url: https://security.ultimatxxxx.com:443/Serverstatus.ashx

当我这样做时:

Webclient.DownloadStringAsync("https://security.ultimatxxxx.com:443/Serverstatus.ashx");

出于测试目的,您可以调用:ultimate-eur 而不是 ultimatxxxx.

For testing purposes you can call: ultimate-eur instead of ultimatxxxx.

它不起作用,但是当我加载没有 https 的普通 URL 时,我没有问题.我必须添加哪个参数才能让 Web 客户端也可以下载字符串?

It does not work, but when I load a normal URL without https I have no problems. Which argument do I have to add so that the Webclient can also download the string?

我想在 Monotouch 中使用该功能,但语言是 C#.

I want to use that feature in Monotouch, but language is C#.

推荐答案

如果您只想接受所有证书,则需要在提出请求之前设置证书检查:

If you just wish to accept all certificates, you'll need to set certificate check, before you make your request:

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

这将接受所有证书.

虽然 - 如果您需要实际检查证书,请执行以下操作:

Although - if you need to actually check the certificate do something like:

ServicePointManager.ServerCertificateValidationCallback =
    (sender, certificate, chain, sslPolicyErrors) => 
    {
        //to check certificate
    };

这篇关于C# WebClient 下载字符串 https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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