查询https页面时出错
本文关键字:出错 https 查询 | 更新日期: 2023-09-27 18:19:20
我正在尝试从https网页下载网页。当我尝试使用浏览器时,它可以工作,但它在c#中不起作用。试过webclient和WebRequest。同样的错误"未经授权"。任何帮助都是感激的。尝试其他解决方案,如使用WebRequest保存cookie。但是没有成功。
我能够从响应中检索标题。身份验证类型是NTLM,在浏览器中我看到一个用户名和密码对话框。在我们的测试服务器上尝试了这个。它工作得很好。但是这个网页不能用
Headers = {Content-Type: text/html服务器:microsoft iis/7.5WWW-Authenticate:谈判,NTLMX-Powered-By: ASP。网日期:2014年8月25日(星期一)20:02:07 GMT内容长度:1293set - cookie: BIGipServerpool_legacy_www = 1269436588.20480.0000;路径=/}
使用webClient using (var client = new WebClient())
{
client.Proxy = null;
client.Credentials = new NetworkCredential(username, password);
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, policy) =>
{
return true;
};
string data = client.DownloadString(url);
return data;
}
使用WebRequest var request = (HttpWebRequest) WebRequest.CreateHttp(url);
request.Credentials = new NetworkCredential(username, password, domain);
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, policy) =>
{
return true;
};
var response = (HttpWebResponse) request.GetResponse();
var stream = response.GetResponseStream();
URL有问题。当我在浏览器中做的时候,它被重定向到正确的URL。小提琴手的原木起到了帮助作用。添加处理http重定向逻辑的代码。