【问题标题】:Using returned XML from an authorised HTTP request in vb.NET在 vb.NET 中使用从授权的 HTTP 请求返回的 XML
【发布时间】:2010-05-03 15:43:23
【问题描述】:

如何在 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())

提前致谢,
内森。

【问题讨论】:

    标签: xml vb.net httpwebrequest webrequest streamreader


    【解决方案1】:

    您不需要创建新的 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());
      }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-08-17
      • 2014-04-19
      • 2018-05-04
      • 2021-04-04
      • 2015-03-08
      • 1970-01-01
      • 2011-05-04
      相关资源
      最近更新 更多