using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.IO; namespace WebAPITest { class Program { public static CookieContainer cookies = new CookieContainer(); public static void Main(string[] args) { //You must pass the base URL and a stock symbol as 2 arguments on the command line //Example usage at the windows command prompt: WebAPITest http://www.junotrade.com INTC //You can go into Visual Studio and choose File | New Project //Choose Visual C# //Choose Console Application //Name it WebAPITest (or any name you want) //copy everything inside of "class Program" over the code generated //Also, the solution can be provided by emailing support@junotrade.com Login(args[0]); GetBuyingPower(args[0]); GetStockQuote(args[0], args[1]); Logout(args[0]); } public static void Login(string url) { //FILL IN USERNAME AND PASSWORD HERE string username = ""; string password = ""; string loginurl = url + "/webapi/login?UserName=" + username + "&Password=" + password; //pass base web api server on command line and logon HttpWebRequest request = (HttpWebRequest)WebRequest.Create(loginurl); request.CookieContainer = cookies; // Set some reasonable limits on resources used by this request request.MaximumAutomaticRedirections = 4; request.MaximumResponseHeadersLength = 4; // Set credentials to use for this request. request.Credentials = CredentialCache.DefaultCredentials; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); //Console.WriteLine("Content length is {0}", response.ContentLength); //Console.WriteLine("Content type is {0}", response.ContentType); // Get the stream associated with the response. Stream receiveStream = response.GetResponseStream(); // Pipes the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8); Console.WriteLine("Response stream received."); Console.WriteLine(readStream.ReadToEnd()); response.Close(); readStream.Close(); } public static void GetBuyingPower(string url) { string loginurl = url + "/webapi/getBuyingPower"; //pass base web api server on command line and logon HttpWebRequest request = (HttpWebRequest)WebRequest.Create(loginurl); request.CookieContainer = cookies; // Set some reasonable limits on resources used by this request request.MaximumAutomaticRedirections = 4; request.MaximumResponseHeadersLength = 4; // Set credentials to use for this request. request.Credentials = CredentialCache.DefaultCredentials; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // Get the stream associated with the response. Stream receiveStream = response.GetResponseStream(); // Pipes the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8); Console.WriteLine("Response stream received."); Console.WriteLine(readStream.ReadToEnd()); response.Close(); readStream.Close(); } public static void GetStockQuote(string url, string symbol) { string loginurl = url + "/webapi/getStockQuote?Symbol=" + symbol; //pass base web api server on command line and logon HttpWebRequest request = (HttpWebRequest)WebRequest.Create(loginurl); request.CookieContainer = cookies; // Set some reasonable limits on resources used by this request request.MaximumAutomaticRedirections = 4; request.MaximumResponseHeadersLength = 4; // Set credentials to use for this request. request.Credentials = CredentialCache.DefaultCredentials; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // Get the stream associated with the response. Stream receiveStream = response.GetResponseStream(); // Pipes the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8); Console.WriteLine("Response stream received."); Console.WriteLine(readStream.ReadToEnd()); response.Close(); readStream.Close(); } public static void Logout(string url) { string loginurl = url + "/webapi/logout"; //pass base web api server on command line and logon HttpWebRequest request = (HttpWebRequest)WebRequest.Create(loginurl); request.CookieContainer = cookies; // Set some reasonable limits on resources used by this request request.MaximumAutomaticRedirections = 4; request.MaximumResponseHeadersLength = 4; // Set credentials to use for this request. request.Credentials = CredentialCache.DefaultCredentials; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); // Get the stream associated with the response. Stream receiveStream = response.GetResponseStream(); // Pipes the stream to a higher level stream reader with the required encoding format. StreamReader readStream = new StreamReader(receiveStream, Encoding.UTF8); Console.WriteLine("Response stream received."); Console.WriteLine(readStream.ReadToEnd()); response.Close(); readStream.Close(); } } }