IASO Backup 2011 SimpleWebReporting

From IASO Wiki
Jump to: navigation, search

How to get XML report via C#?

using System;
using System.Collections;
using System.Collections.Generic;
using System.Net;
using System.IO;
using System.Text;
using System.Security.Cryptography.X509Certificates;
 
// If you have invalid server certificate
public class TrustAllCertificatePolicy : System.Net.ICertificatePolicy
{
    public TrustAllCertificatePolicy()
    {
 
    }
 
    public bool CheckValidationResult(ServicePoint sp,
     X509Certificate cert, WebRequest req, int problem)
    {
        return true;
    }
}
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Net.ServicePointManager.CertificatePolicy = new TrustAllCertificatePolicy();
 
            string username = "%your_engine_user%";
            string password = "%your_engine_password%";
 
            ASCIIEncoding encoding = new ASCIIEncoding();
            string postData = "user=" + username;
            postData += ("&password=" + password);
            byte[] data = encoding.GetBytes(postData);
 
            Hashtable parameters = new Hashtable();
 
            #region Login
            {
                HttpWebRequest request =
                    (HttpWebRequest)WebRequest.Create("https://%your_engine_host%:%your_simplewebreporting_port%/reporting/login");
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = data.Length;
                Stream newStream = request.GetRequestStream();
                // Send the data.
                newStream.Write(data, 0, data.Length);
                newStream.Close();
 
                HttpWebResponse WebResp = (HttpWebResponse)request.GetResponse();
 
                string query = WebResp.ResponseUri.Query;
 
                WebResp.Close();
 
                if (query[0] == '?')
                {
                    query = query.Substring(1, query.Length - 1);
                }
 
                List<string> rawParamaters = new List<string>(query.Split('&'));
 
                foreach (string str in rawParamaters)
                {
                    List<string> list = new List<string>(str.Split('='));
                    parameters.Add(list[0], list[1]);
                }
            }
            #endregion
 
            string auth = (string)parameters["AUTH"];
 
            #region Get accounts list
            {
                HttpWebRequest request =
                    (HttpWebRequest)WebRequest.Create("https://%your_engine_host%:%your_simplewebreporting_port%/reporting/accounts.xml?AUTH=" + auth);
                request.Method = "GET";
 
                HttpWebResponse WebResp = (HttpWebResponse)request.GetResponse();
 
                Stream newStream = WebResp.GetResponseStream();
                StreamReader streamReader = new StreamReader(newStream, Encoding.ASCII);
                string responseData = streamReader.ReadToEnd();
                streamReader.Close();
                WebResp.Close();
 
                Console.Write(responseData);
            }
            #endregion
        }
    }
}
Personal tools
Namespaces
Variants
Actions
Navigation
Downloads
Knowledge Base
Support
Toolbox