using System; using System.Drawing; using System.IO; using System.Text.RegularExpressions; using System.Net; public static class VoiceBotScript { public static void Run(IntPtr windowHandle) { string url = "http://thecatapi.com/api/images/get?format=xml&type=gif&results_per_page=1"; //create an HttpWebRequest with the url HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); //change this to "POST" to use the post verb request.Method = "GET"; //if you need to modify any headers, here would be the place to do it //this variable will contain the xml returned from the server string xml = ""; //get the response from the server using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { //if the status isn't equal to OK exit the script if (response.StatusCode != HttpStatusCode.OK) return; //open the response stream and get the data as a string using (Stream stream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream ?? Stream.Null)) xml = reader.ReadToEnd(); } } //if there is no response, exit the script if (string.IsNullOrEmpty(xml)) return; //strip the url from the xml open it in the browser string catImageUrl = Regex.Match(xml, "(?<=).+?(?=)").ToString(); if (!string.IsNullOrEmpty(catImageUrl)) BFS.Web.OpenUrl(catImageUrl); } }