1
我想加載一個HttpWebResponse到一個XmlDocument,並得到異常「根數據無效。行1,位置1」。如果我輸出響應到控制檯,我會得到「system.net.connectstream」。憑據似乎不是我的問題,因爲如果我輸入一個不正確的密碼,我的異常更改爲404錯誤。這裏是我的代碼...來自HttpWebRequest的無效數據HttpWebResponse C#
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());
謝謝!
StreamReader允許我抓取數據並看到我正在獲取正確的數據,但是當我將XMLDocument.Load放回時,我得到相同的錯誤。這裏是流的樣子(刪除了數據)... – MCR 2012-08-02 14:04:35
{「messages」:{「message」:「1 devices(s)returned。」},「devices」:{「device」:{「@ id 「:」00「,」uuid「:」00000000「,」phonenumber「:」000000「,」用戶名「:」0000「,」姓名「:」Guy,Somebody「,」platform「 os「:」III「,」version「:」1.1.1「}},」appName「:」someApp「} – MCR 2012-08-02 14:05:52
@MCR:好的,這是JSON,不是XML ... – 2012-08-02 14:07:21