我正在尝试将 HttpWebResponse 加载到 XmlDocument 中,并收到异常“根级别的数据无效。第 1 行,位置 1”。如果我将响应输出到控制台,我会得到“system.net.connectstream”。凭据似乎不是我的问题,因为如果我输入了错误的密码,我的异常会更改为 404 错误。这是我的代码...
string username = "username";
string password = "password";
string url = "https://myurl.com";
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Credentials = new NetworkCredential(username, password);
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
XmlDocument xmlDoc = new XmlDocument();
Console.WriteLine(response.GetResponseStream());
xmlDoc.Load(response.GetResponseStream());
谢谢!