/// <summary> /// Suorittaa kyselyn Wilman Json rajapintaan ja palauttaa merkkijonon. /// </summary> /// <param name="service"></param> /// <returns></returns> public string Login(string service) { // Initiate the HttpWebRequest with session support with CookiedFactory if (String.IsNullOrEmpty(service)) { request = CookiedRequestFactory.CreateHttpWebRequest(wilmaUrl + "index_json"); } else { request = CookiedRequestFactory.CreateHttpWebRequest(wilmaUrl + service); } // Serialize the response to json request.Method = "GET"; request.ContentType = "application/json"; request.Accept = "application/json"; // Get the login status from the service response = (HttpWebResponse)request.GetResponse(); var reader = new StreamReader(response.GetResponseStream()); string jsonResponseString = reader.ReadToEnd(); values = JsonConvert.DeserializeObject <IndexJson>(jsonResponseString); reader.Close(); response.Close(); // DO the HASH ComputeHash(values); return(jsonResponseString); }
/// <summary> /// Kirjaudutaan evästeiden kanssa /// </summary> /// <param name="LoginUrl"></param> /// <returns></returns> public string LoginWCookies(string LoginUrl) { string loginParameters = "Login="******"&Password="******"&SessionId=" + values.SessionID + "&ApiKey=" + "sha1:" + hash + "&format=json"; var bytes = Encoding.UTF8.GetBytes(loginParameters); request = CookiedRequestFactory.CreateHttpWebRequest(LoginUrl + "?" + loginParameters); request.Method = "POST"; request.ContentType = "application/json"; request.Accept = "application/json"; // Send the json data to the Rest service var postStream = request.GetRequestStream(); postStream.Write(bytes, 0, bytes.Length); postStream.Close(); // Get the login status from the service HttpWebResponse response; try { response = (HttpWebResponse)request.GetResponse(); var reader = new StreamReader(response.GetResponseStream()); var jsonResponseString = reader.ReadToEnd(); values = JsonConvert.DeserializeObject <IndexJson>(jsonResponseString); reader.Close(); response.Close(); return(jsonResponseString); } catch (Exception ex) { return(ex.Message.ToString()); } }
public static ServiceStatus Login(AppUserCredentail credentail) { // Serialize the students to json var serializer = new JavaScriptSerializer(); var jsonRequestString = serializer.Serialize(credentail); var bytes = Encoding.UTF8.GetBytes(jsonRequestString); // Initiate the HttpWebRequest with session support with CookiedFactory var request = CookiedRequestFactory.CreateHttpWebRequest(LoginUrl); request.Method = "POST"; request.ContentType = "application/json"; request.Accept = "application/json"; // Send the json data to the Rest service var postStream = request.GetRequestStream(); postStream.Write(bytes, 0, bytes.Length); postStream.Close(); // Get the login status from the service var response = (HttpWebResponse)request.GetResponse(); var reader = new StreamReader(response.GetResponseStream()); var jsonResponseString = reader.ReadToEnd(); reader.Close(); response.Close(); // Deserialize the json and return the result return(serializer.Deserialize <ServiceStatus>(jsonResponseString)); }
public string Post(string service, WilmaMsg msg) { string recipients = String.Empty; if (!String.IsNullOrEmpty(msg.r_teacher)) { recipients = "&r_teacher=" + msg.r_teacher; } if (!String.IsNullOrEmpty(msg.r_personnel)) { recipients += "&r_personnel=" + msg.r_personnel; } string loginParameters = "format=json&bodytext=" + msg.bodytext + "&Subject=" + msg.Subject + recipients + "&Formkey=" + msg.FormKey; // Initiate the HttpWebRequest with session support with CookiedFactory if (String.IsNullOrEmpty(service)) { request = CookiedRequestFactory.CreateHttpWebRequest(wilmaUrl + "messages/compose"); } else { request = CookiedRequestFactory.CreateHttpWebRequest(wilmaUrl + service + "?" + loginParameters); } // Serialize the response to json request.Method = "POST"; request.ContentType = "application/json"; request.Accept = "application/json"; // Serialize the msg to json var serializer = new JavaScriptSerializer(); var jsonRequestString = serializer.Serialize(msg); //var bytes = Encoding.UTF8.GetBytes(jsonRequestString); var bytes = Encoding.UTF8.GetBytes(loginParameters); // Send the json data to the Rest service string jsonResponseString = String.Empty; try { Stream postStream = request.GetRequestStream(); postStream.Write(bytes, 0, bytes.Length); postStream.Close(); // Get the login status from the service var response = (HttpWebResponse)request.GetResponse(); var reader = new StreamReader(response.GetResponseStream()); jsonResponseString = reader.ReadToEnd(); // values = JsonConvert.DeserializeObject<IndexJson>(jsonResponseString); reader.Close(); response.Close(); } catch (Exception ex) { jsonRequestString = ex.Message.ToString(); } // DO the HASH ComputeHash(values); return(jsonResponseString); }
public static ServiceResult <List <Student> > GetStudentsWithCookie() { var request = CookiedRequestFactory.CreateHttpWebRequest(GetStudentsUrl); return(GetStudents(request)); }