public string GetMcolStatsJson() { var request = (HttpWebRequest)WebRequest.Create(@"https://www.warren-ayling.me.uk:8443/api/dashboard/mcol/stats"); request.ContentType = "application/json; charset=utf-8"; request.Headers.Set("x-auth", MainActivity.jwtToken); //Comment out if debugging on android device if (MainActivity._localProxy != null) { request.Proxy = new WebProxy("proxy.logica.com", 80); } string json = ""; //Get response code without exception var response = HttpWebResponseExt.GetResponseNoException(request); if (response.StatusCode == HttpStatusCode.OK) { using (var sr = new StreamReader(response.GetResponseStream())) { json = sr.ReadToEnd(); //Praise the lord for this line below json = JToken.Parse(json).ToString(); ////Remove \ and quotes wrapped round json //json = json.Replace(@"\", string.Empty); //json = json.Substring(1, json.Length - 2); return(json); } } else if (response.StatusCode == HttpStatusCode.Unauthorized) { MCOLTabbedDash.dataExpired = true; } return(json); }
public string GetMcolServAlertsJson() { var request = (HttpWebRequest)WebRequest.Create(@"https://www.warren-ayling.me.uk:8443/api/dashboard/mcol/serveralerts"); request.ContentType = "application/json; charset=utf-8"; request.Headers.Set("x-auth", MainActivity.jwtToken); if (MainActivity._localProxy != null) { request.Proxy = new WebProxy("proxy.logica.com", 80); } string json = ""; //Get response code without exception var response = HttpWebResponseExt.GetResponseNoException(request); if (response.StatusCode == HttpStatusCode.OK) { using (var sr = new StreamReader(response.GetResponseStream())) { json = sr.ReadToEnd(); //Praise the lord for this line below json = JToken.Parse(json).ToString(); return(json); } } else if (response.StatusCode == HttpStatusCode.Unauthorized) { MCOLTabbedDash.dataExpired = true; } return(json); }
public bool ValidateUserLogin(TextView user, TextView pwd, TextView incorrectCredTxt, bool prompt) { var uri = new Uri("https://www.warren-ayling.me.uk:8443/api/user/login"); string json = string.Format("{{\"username\":\"{0}\"," + "\"passwd\":\"{1}\"}}", user.Text.Trim(), pwd.Text.Trim()); //Comment out if NOT using groupinfra network _localProxy = new WebProxy("proxy.logica.com", 80); var httpWebRequest = (HttpWebRequest)WebRequest.Create(uri); //Below needs to be commented out if i'm debugging on android device if (MainActivity._localProxy != null) { httpWebRequest.Proxy = new WebProxy("proxy.logica.com", 80); } httpWebRequest.ContentType = "application/json"; httpWebRequest.Accept = "application/json"; httpWebRequest.Method = "POST"; using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { streamWriter.Write(json); streamWriter.Flush(); streamWriter.Close(); } //Get response code var httpResponse = HttpWebResponseExt.GetResponseNoException(httpWebRequest); var result = ""; using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { result = streamReader.ReadToEnd(); } //if credentials are ok then go to menu if (httpResponse.StatusCode == HttpStatusCode.OK) { //Store jwtToken jwtToken = result; //Reset data expiry MCOLTabbedDash.dataExpired = false; //Secret key as bytes byte[] secKeyBytes = Encoding.UTF8.GetBytes(secretKey); if (!prompt) { //Go to menu dashboard page Intent menu = new Intent(this.ApplicationContext, typeof(MenuActivity)); userName = user.Text.Trim(); StartActivity(menu); } return(true); } else { incorrectCredTxt.Visibility = ViewStates.Visible; return(false); } }