在 vb.NET 中使用授权 HTTP 请求返回的 XML

发布于 2024-08-31 03:38:46 字数 592 浏览 8 评论 0原文

如何在 xmltextreader 中使用阅读器返回的 XML?

            ' Create the web request  
        request = DirectCast(WebRequest.Create("https://mobilevikings.com/api/1.0/rest/mobilevikings/sim_balance.xml"), HttpWebRequest)

        ' Add authentication to request  
        request.Credentials = New NetworkCredential("username", "password")

        ' Get response  
        response = DirectCast(request.GetResponse(), HttpWebResponse)

        ' Get the response stream into a reader  
        reader = New StreamReader(response.GetResponseStream())

预先感谢,
内森。

How can I use the returned XML from the reader in a xmltextreader?

            ' Create the web request  
        request = DirectCast(WebRequest.Create("https://mobilevikings.com/api/1.0/rest/mobilevikings/sim_balance.xml"), HttpWebRequest)

        ' Add authentication to request  
        request.Credentials = New NetworkCredential("username", "password")

        ' Get response  
        response = DirectCast(request.GetResponse(), HttpWebResponse)

        ' Get the response stream into a reader  
        reader = New StreamReader(response.GetResponseStream())

Thanks in advance,
Nathan.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

荒路情人 2024-09-07 03:38:46

您不需要创建新的 StreamReader,只需使用 GetResponseStream

//Get the Response Stream from the URL 
Stream responseStream = response.GetResponseStream(); 

// Read the Response Stream using XmlTextReader 
XmlTextReader reader = new XmlTextReader(responseStream); 

//read through all the nodes
while(reader.Read())
{
  //find the item node and read its value
  if(reader.Name == "item")
  {
        Console.Write(reader.ReadString());
  }
}

You don't need to create new StreamReader, just use GetResponseStream

//Get the Response Stream from the URL 
Stream responseStream = response.GetResponseStream(); 

// Read the Response Stream using XmlTextReader 
XmlTextReader reader = new XmlTextReader(responseStream); 

//read through all the nodes
while(reader.Read())
{
  //find the item node and read its value
  if(reader.Name == "item")
  {
        Console.Write(reader.ReadString());
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文