Exemple #1
0
        /// <summary>
        /// Put処理
        /// </summary>
        /// <param name="json">JSON文字列</param>
        /// <returns>結果</returns>
        protected async Task<KintaiResult> KintaiPutAsync(string json)
        {
            UriBuilder ub = new UriBuilder("https", this.host, 443, @"k/v1/record.json");

            HttpClientHandler handler = new HttpClientHandler();

            HttpClient cl = new HttpClient(handler);
            cl.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            cl.DefaultRequestHeaders.Add("X-Cybozu-Authorization", this.XCybozuAuthorizationBase64(this.id, this.pass));
            cl.DefaultRequestHeaders.Add("Host", ub.Host + ":" + ub.Port);

            StringContent content = new StringContent(json, Encoding.UTF8, "application/json");

            HttpResponseMessage httpResponse = null;
            try
            {
                httpResponse = await cl.PutAsync(ub.Uri, content);
            }
            catch
            {
                throw;
            }
            if (!httpResponse.IsSuccessStatusCode)
            {
                KintaiResult result = new KintaiResult
                {
                    IsResult = false
                };
                return result;
            }
            string resultString = await httpResponse.Content.ReadAsStringAsync();

            KintaiResult resultJson = JValue.Parse(resultString).ToObject<KintaiResult>();

            return resultJson;
        }
Exemple #2
0
        /// <summary>
        /// 出勤打刻
        /// </summary>
        /// <param name="idm">カード番号</param>
        /// <returns>結果</returns>
        public async Task<KintaiResult> CreateAttendanceRecord(string idm)
        {
            Console.WriteLine("出勤打刻 - start : " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));
            UriBuilder ub = new UriBuilder("https", this.host, 443, @"k/v1/record.json");

            HttpClientHandler handler = new HttpClientHandler();

            HttpClient cl = new HttpClient(handler);
            cl.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
            cl.DefaultRequestHeaders.Add("X-Cybozu-Authorization", this.XCybozuAuthorizationBase64(this.id, this.pass));
            cl.DefaultRequestHeaders.Add("Host", ub.Host + ":" + ub.Port);

            string json = this.MakeCreateRecord(idm);

            StringContent content = new StringContent(json, Encoding.UTF8, "application/json");

            HttpResponseMessage httpResponse = null;
            try
            {
                httpResponse = await cl.PostAsync(ub.Uri, content);
            }
            catch
            {
                throw;
            }
            if (!httpResponse.IsSuccessStatusCode)
            {
                KintaiResult result = new KintaiResult
                {
                    IsResult = false
                };
                return result;
            }
            string resultString = await httpResponse.Content.ReadAsStringAsync();

            KintaiResult resultJson = JValue.Parse(resultString).ToObject<KintaiResult>();

            Console.WriteLine("出勤打刻 - end : " + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));
            return resultJson;
        }