c# - 从 .net 代码使用雅虎网络服务

标签 c# xml web-services feed

我有以下代码,我在其中尝试发出查询 yahoo api 的请求以返回 whoid。但是我无法生成 XML 来查询它,错误没有显示。

private string getWOEID()
{
 string woeID = "";

  String reqUrl = "http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%20where%20text%3D%22farnborough%2Champshire%2Cuk%22&format=xml";
  HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(reqUrl);
  //load the response into a response object
  WebResponse resp = wr.GetResponse();
  // create a new stream that can be placed into an XmlTextReader
  Stream str = resp.GetResponseStream();
  XmlTextReader reader = new XmlTextReader(str);
  reader.XmlResolver = null;
  // create a new Xml document and loading feed data in to it
  XmlDocument xmldoc = new XmlDocument();
  xmldoc.Load(reader);

  //query the woeid with using linq 
  XDocument doc = XDocument.Parse(xmldoc.ToString());
  woeID = doc.Descendants()
                .Where(element => element.Name == "woeid")
                .FirstOrDefault().Value;
  return woeID;

    }

是否有更好/更容易从响应生成 XML 文档的方法?

非常感谢,

最佳答案

比我想象的容易得多,请参阅 http://developer.yahoo.com/dotnet/howto-xml_cs.html

    String reqUrl = "http://query.yahooapis.com/v1/public/yql?q=select%20woeid%20from%20geo.places%20where%20text%3D%22farnborough%2Champshire%2Cuk%22&format=xml";

XmlDocument doc = new XmlDocument();
 doc.Load(reqUrl);

关于c# - 从 .net 代码使用雅虎网络服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1949555/

相关文章:

xmllint 和 xpath 从 https ://mail. google.com/mail/feed/atom 解析 xml 数据

iphone - 如何安全地将 JSON 传输到 iOS 应用程序或从 iOS 应用程序传输 JSON?

c# - 将异步/等待转换为 Task.ContinueWith

c# - 通过 XML 迭代?

c# - 如何从 C#.NET 代码生成 JS

java - xmlunit 在相同的 xml 中发现差异

c# - .Net 4.5 中的 Microsoft.Windows.Shell 命名空间等效项

python - 使用 Dom (minidom) 将标签添加到 XML 文件

java - 使用可选参数构建 Liferay Web 服务

iphone - 如何在 iPhone 中使用 PhoneGap 调用基于 SOAP 的 Web 服务?