2010-05-03 69 views
0

如何在xmltextreader中使用從讀取器返回的XML?在vb.NET中使用從授權HTTP請求返回的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()) 

由於提前,
彌敦道。

回答

0

你並不需要創建新的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()); 
    } 
}