在网络浏览器中,我通常可以加载以下网址: https://security.ultimatxxxx.com:443/Serverstatus.ashx
当我这样做时:
Webclient.DownloadStringAsync("https://security.ultimatxxxx.com:443/Serverstatus.ashx");
出于测试目的,您可以调用:ultimate-eur
而不是ultimatxxxx
。
它不起作用,但是当我加载没有https的普通URL时,我没有问题。我必须添加哪个参数才能使 Web 客户端也可以下载字符串?
我想在Monotouch中使用该功能,但语言是C#。
如果您只想接受所有证书,则需要在提出请求之前设置证书检查:
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
这将接受所有证书。
虽然 - 如果您需要实际检查证书,请执行以下操作:
ServicePointManager.ServerCertificateValidationCallback =
(sender, certificate, chain, sslPolicyErrors) =>
{
//to check certificate
};
一个可能的原因可能是某些网站为不同的浏览器提供不同的结果。
您可以尝试提供浏览器信息以假装调用来自浏览器。
var client = new WebClient();
client.Headers["User-Agent"] = "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.15) Gecko/20110303 Firefox/3.6.15";
string download = client.DownloadString("https://security.ultimatxxxx.com:443/Serverstatus.ashx");
或
您尚未绑定
Aysnc
调用的completedEvent
。