我正在尝试从网址下载xml文件,但是我收到此错误: "远程服务器返回错误(401)未授权"。此外,此网页需要一些凭据。
我在问你之前搜索了不同的主题,但我没有找到解决方案...
以下是我尝试过的两个版本的代码,但没有成功:
try
{
WebClient wClient = new WebClient();
wClient.Credentials = new NetworkCredential(nni, pwd);
var dlString = wClient.DownloadString(url);
//Stream data = wClient.OpenRead(url);
//var reader = new XmlTextReader(wClient.OpenRead(url));
//doc.LoadXml();
doc.Load(wClient.OpenRead(url));
Console.WriteLine(doc.InnerText);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(xmlUrl);
WebClient client = new WebClient();
client.Credentials = new NetworkCredential(nni, pwd);
string htmlCode = client.DownloadString(xmlUrl);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
你能帮帮我吗?