コード例 #1
0
ファイル: API.cs プロジェクト: fi2016/open-sense-viewer
 public bool CheckAuth(string username, string password)
 {
     try
     {
         webRequest             = (HttpWebRequest)WebRequest.Create("https://apps.mikolai-sebastian.de/api/v1/open_sense_viewer/auth");
         webRequest.ContentType = "application/json";
         webRequest.Method      = "POST";
         writer = new StreamWriter(webRequest.GetRequestStream());
         string requestJson = "{\"platform\":\"" + Platform + "\", \"username\":\"" + username + "\", \"password\":\"" + password + "\"}";
         writer.Write(requestJson);
         writer.Flush();
         writer.Close();
         webResponse = (HttpWebResponse)webRequest.GetResponse();
         reader      = new StreamReader(webResponse.GetResponseStream());
         string             responseJson = reader.ReadToEnd();
         GenericApiResponse response     = JsonConvert.DeserializeObject <GenericApiResponse>(responseJson);
         if (response.Status.Equals("success") && response.Id == 200 && response.Message.Equals("Authorized"))
         {
             Username = username;
             Password = password;
             return(true);
         }
     }
     catch (Exception)
     {
         MessageBox.Show("Die API-Anfrage konnte nicht durchgeführt werden!", "Open Sense Viewer", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     return(false);
 }
コード例 #2
0
        public bool checkAuth(string username, string password)
        {
            webRequest             = (HttpWebRequest)WebRequest.Create("https://apps.mikolai-sebastian.de/api/v1/open_sense_viewer/auth");
            webRequest.ContentType = "application/json";
            webRequest.Method      = "POST";
            writer = new StreamWriter(webRequest.GetRequestStream());
            string requestJson = "{\"platform\":\"" + Platform + "\", \"username\":\"" + username + "\", \"password\":\"" + password + "\"}";

            writer.Write(requestJson);
            writer.Flush();
            writer.Close();
            webResponse = (HttpWebResponse)webRequest.GetResponse();
            reader      = new StreamReader(webRequest.GetRequestStream());
            string             responseJson = reader.ReadToEnd();
            GenericApiResponse response     = JsonConvert.DeserializeObject <GenericApiResponse>(responseJson);

            if (response.Status.Equals("success") && response.Id == 200 && response.Message.Equals("Authorized"))
            {
                return(true);
            }
            return(false);
        }