C# 查询https网页时出错
我正在尝试从https网页下载该网页。当我尝试使用浏览器时,它可以工作,但在C语言中不工作。我尝试了webclient和WebRequest。同样的错误未经授权。感谢您的帮助。尝试寻找其他解决方案,如使用WebRequest保存cookies。但是没有起作用 我能够从响应中检索标题。身份验证类型是NTLM,在浏览器中我看到一个带有用户名和密码的对话框。在我们的测试服务器上尝试了这个。它很好用。但不适用于此网页 标题={内容类型:text/html 服务器:Microsoft IIS/7.5 WWW认证:协商,NTLM X-Powered-By:ASP.NET 日期:2014年8月25日星期一20:02:07 GMT 内容长度:1293 设置Cookie:BIGipServerpool_legacy_www=1269436588.20480.0000;路径=/ } 使用webClientC# 查询https网页时出错,c#,https,httpwebrequest,webclient,unauthorized,C#,Https,Httpwebrequest,Webclient,Unauthorized,我正在尝试从https网页下载该网页。当我尝试使用浏览器时,它可以工作,但在C语言中不工作。我尝试了webclient和WebRequest。同样的错误未经授权。感谢您的帮助。尝试寻找其他解决方案,如使用WebRequest保存cookies。但是没有起作用 我能够从响应中检索标题。身份验证类型是NTLM,在浏览器中我看到一个带有用户名和密码的对话框。在我们的测试服务器上尝试了这个。它很好用。但不适用于此网页 标题={内容类型:text/html 服务器:Microsoft IIS/7.5 WW
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重定向逻辑的代码