using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace GetWowzaConnectionsInformation
{
class Program
{
static void Main(string[] args)
{
string url = @"http://127.0.0.1:8086/connectioncounts";
var webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Method = "GET";
webRequest.ContentType = "application/xml";
webRequest.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:28.0) Gecko/20100101 Firefox/28.0";
webRequest.ContentLength = 0; // added per comment
string autorization = "username" + ":" + "password";
byte[] binaryAuthorization = System.Text.Encoding.UTF8.GetBytes(autorization);
autorization = Convert.ToBase64String(binaryAuthorization);
autorization = "Basic " + autorization;
webRequest.Headers.Add("AUTHORIZATION", autorization);
var webResponse = (HttpWebResponse)webRequest.GetResponse();
if (webResponse.StatusCode != HttpStatusCode.OK) Console.WriteLine("{0}", webResponse.Headers);
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(webResponse.GetResponseStream());
XmlNodeList nodeList = xmlDoc.GetElementsByTagName("VHost");
foreach (XmlNode parentNode in nodeList)
{
if (parentNode is XmlElement)
{
XmlElement element = (XmlElement)parentNode;
XmlNodeList ConnectionsCurrent = element.GetElementsByTagName("ConnectionsCurrent");
foreach (XmlNode childNode in ConnectionsCurrent)
{
//Console.Write("<" + ((XmlElement)childNode).Name + "> ");
Console.Write(((XmlElement)childNode).ChildNodes.Item(0).Value);
}
}
}
Console.ReadLine();
}
}
}
留言列表