|
|
#1 |
|
Junior Member
Join Date: Jul 2004
Posts: 2
|
ASP.NET Connection
I'm trying to get statistics with asp.net. I use the XmlTextReader to put the tables into a dataset.
Dim reader as XmlTextReader = New XmlTextReader("http://localhost:8000/admin.cgi?pass=7577&mode=viewxml&page=0") The problem is that you have to pass a user-agent header with mozilla in it. I've been looking all over, but I could not find a proper solution to get it work. Does anyone know how to this in this case or another solution for asp.net to get the statistics from the XML. |
|
|
|
|
|
#2 |
|
Junior Member
Join Date: Jul 2004
Posts: 2
|
I finally found a script thats works, for those who are interested:
Dim webRequest As HttpWebRequest = CType(WebRequest.Create("http://localhost:8000/admin.cgi?pass=pass&mode=viewxml&page=0") , HttpWebRequest) webRequest.Credentials = CredentialCache.DefaultCredentials webRequest.Accept = "text/xml" webRequest.UserAgent = "Mozilla" Dim webResponse As HttpWebResponse = CType(webRequest.GetResponse(), HttpWebResponse) Dim responseStream As System.IO.Stream = webResponse.GetResponseStream() Dim reader As XmlTextReader = New XmlTextReader(responseStream) |
|
|
|
|
|
#3 |
|
Junior Member
Join Date: Nov 2003
Location: Springfield, IL.
Posts: 12
|
asp.net question
that works perfectly to get the xmltext, but how did you iterate through it and pick out the values you wanted?
|
|
|
|
|
|
#4 | |
|
Junior Member
Join Date: Apr 2005
Posts: 3
|
Quote:
|
|
|
|
|
|
|
#5 |
|
Junior Member
Join Date: Apr 2005
Posts: 1
|
Not sure I understand your question MRmP. This would be an aspx page you can use the code to retrieve the xml stats from the shoutcast server, then use asp.net code to render the stats you want to display. The code above handles retrieving the xml from the shoutcast server. I then use the XmlDocument object and XPath to retrieve values for specific nodes in the xml tree. I did my code a little different from rodyla and my code is in C# not VB.Net. Here's an example:
// This part of the code is similar to rodyla's HttpWebRequest webRequest; HttpWebResponse webResponse; webRequest = (HttpWebRequest)WebRequest.Create(xmlfile); webRequest.Credentials = CredentialCache.DefaultCredentials; webRequest.Accept = "text/xml"; webRequest.UserAgent = "Mozilla"; webResponse = (HttpWebResponse)webRequest.GetResponse(); //This is where the code starts to differ //I read the GetResponseStream into a streamreader StreamReader streamreader = new StreamReader(webResponse.GetResponseStream(),Encoding.UTF8); //then read the resonsestream into a string string xmlstring = streamreader.ReadToEnd(); //now we create an instance of XmlDocument object XmlDocument xmldoc = new XmlDocument(); try { // and load the xmlstring into the xmldocument xmldoc.LoadXml( xmlstring ); //now we can search through the xml to find the xml nodes with the values we're looking for. //in my example I'm only going to look for CurrentListeners //I'm going to use the StringBuilder object to concat the output string StringBuilder sb = new StringBuilder(); XmlNode node = null; //if you need a reference to learn how to use xpath to query xml: www.w3schools.com/xpath/xpath_syntax.asp string xpathquery = "/SHOUTCASTSERVER/CURRENTLISTENERS"; //in this case we'll select a single xml node node = _xmldoc.SelectSingleNode(xpathquery); if (node != null) { sb.Append( "currentlisteners=" + node.InnerText ); } Page.Response.Write( sb.ToString() ); } catch(Exception ex) { Response.Write("<br>Error: <br>" + ex.Message); } |
|
|
|
|
|
#6 |
|
Junior Member
Join Date: May 2005
Posts: 1
|
combined solution
thanks a lot for your twice solutions , i`ve combined them in one solution , it can be helpful alos , so i decided to put it , using c#
first add those in the header of your page using System.Net; using System.IO; using System.Xml ; private void getStat() { int status; HttpWebRequest myReq ; HttpWebResponse myResp; myReq = (HttpWebRequest)WebRequest.Create("http://67.18.183.219:7070/admin.cgi?pass=yourpass&mode=viewxml"); myReq.Credentials = CredentialCache.DefaultCredentials; myReq.UserAgent = "Mozilla"; myResp = (HttpWebResponse)myReq.GetResponse(); Stream responseStream = myResp.GetResponseStream(); XmlTextReader xReader = new XmlTextReader(responseStream); while (xReader.Read()) { if (xReader.NodeType == XmlNodeType.Element ) { if (xReader.Name == "STREAMSTATUS") status = int.Parse(xReader.ReadString()); } } if (status == 1 ) mirror1.Src = "lampa.gif"; //hear i change a // picture of a lamp to give the feeling of being online } |
|
|
|
|
|
#7 |
|
Junior Member
Join Date: May 2005
Location: Germany
Posts: 4
|
ASP
Have a guy a ASP only script?
|
|
|
|
|
|
#8 |
|
Moderator
Join Date: Feb 2005
Location: USA
Posts: 3,990
|
This might get you started... Not all stats get written using this, but you get the idea.
extURL = "http://[server]:[port]/admin.cgi?pass=changeme&mode=viewxml" set xmlDoc = createObject("Msxml.DOMDocument") xmlDoc.async = false xmlDoc.setProperty "ServerHTTPRequest", true xmlDoc.load(extURL) playtime = "" If (xmlDoc.parseError.errorCode <> 0) then ' Shoutcast server is not running ShowCurrentSong = "Server Down for Maintenance" History = "" Else ServerStatus = xmlDoc.SelectSingleNode("//STREAMSTATUS").text If serverstatus = "1" Then StationName = xmlDoc.SelectSingleNode("//SERVERTITLE").text BitRate = xmlDoc.SelectSingleNode("//BITRATE").text ServerVersion = xmlDoc.SelectSingleNode("//VERSION").text MediaType = xmlDoc.SelectSingleNode("//CONTENT").text CurrentSong = xmlDoc.SelectSingleNode("//SONGTITLE").text If instr(CurrentSong,"-") > 0 Then ShowCurrentSong = CurrentSong End If Users = xmlDoc.SelectSingleNode("//CURRENTLISTENERS").text MaxUsers = xmlDoc.SelectSingleNode("//MAXLISTENERS").text Set SongHistory = xmlDoc.SelectNodes("//SONG") Set UserList = xmlDoc.SelectNodes("//LISTENER") For Each Song In SongHistory If NOT Song.SelectSingleNode("TITLE").text = CurrentSong Then ThisSong = Song.SelectSingleNode("TITLE").text History = History & ThisSong & "<br>" & chr(13) End If Next For Each User In UserList ConnectedUsers = ConnectedUsers & User.SelectSingleNode("HOSTNAME").text & "<br>" Next Else ' SHOUTcast is up, but no source... ShowCurrentSong = "Currently Off The Air" SongHistory = "" End If End If response.write "<b>Now Playing</b><br>" & ShowCurrentSong & "<br><br><b>Song History</b><br>" & History & "<br><b>Listeners</b><br>" & ConnectedUsers |
|
|
|
|
|
#9 |
|
Junior Member
Join Date: May 2005
Location: Germany
Posts: 4
|
absolut great!
thank you a lot!!
|
|
|
|
![]() |
|
|||||||
| Thread Tools | Search this Thread |
| Display Modes | |
|
|