【发布时间】:2012-03-26 05:41:39
【问题描述】:
我正在尝试加载文档,请参阅下面的代码
try
{
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
XmlReader responseReader = XmlReader.Create(response.GetResponseStream());
XDocument docs = XDocument.Load(responseReader.Read());
上面这行告诉我 xdocument.Load 有一些无效参数。
//XDocument docs = XDocument.Load(response.GetResponseStream());
此行未加载任何内容 Docs 为空
XDocument docs = XDocument.Load(responseReader);
这一行没有给出任何重载错误,但什么也不返回。
List<string> books = docs.Descendants("Test")....."Remaining QQuery"
【问题讨论】:
-
你能贴出实际的错误信息吗?
-
无法从 Bool 转换为字符串 'system.xml.linq.xdocument.Load(string') 的最佳重载方法匹配有一些无效参数
-
无需创建XmlReader;你应该能够做到: XDocument docs = XDocument.Load(new StreamReader(response.GetResponseStream()));之后文档是否仍然为空(检查 docs.Nodes.Count)?如果是,是时候查看响应本身了。
-
这解决了我的问题。非常感谢。
-
@SmilingLily 没问题 - 如果您在响应本身遇到任何问题,我会在下面为您提供更多故障排除提示。令人惊讶的是,一行代码可以解决多少编程问题,不是吗!