Beispiel #1
0
        /// <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);
        }
Beispiel #2
0
        /// <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
            var 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);
        }
Beispiel #3
0
        public void ComputeHash(IndexJson indexJson)
        {
            string plain;

            // Hash
            byte[] temp;
            plain = username + "|" + indexJson.SessionID + "|" + companySpesificKey;
            SHA1 sha = new SHA1CryptoServiceProvider();

            // This is one implementation of the abstract class SHA1.
            temp = sha.ComputeHash(Encoding.UTF8.GetBytes(plain));

            //storing hashed value into byte data type
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < temp.Length; i++)
            {
                sb.Append(temp[i].ToString("x2"));
            }
            hash = sb.ToString();
        }