예제 #1
0
        public static async Task <string> GetContentAsync(CareviewApiConnection conn, string url)
        {
            var rs = await conn.HttpClient.GetAsync(url);

            if (rs.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception(rs.StatusCode.ToString() + ": " + rs.ReasonPhrase);
            }
            return(await rs.Content.ReadAsStringAsync());
        }
예제 #2
0
        public static async Task <string> PostContentAsync(CareviewApiConnection conn, string url, object payload)
        {
            var body    = JsonConvert.SerializeObject(payload);
            var content = new StringContent(body, System.Text.Encoding.UTF8, "application/json");

            var rs = await conn.HttpClient.PostAsync(url, content);

            if (rs.StatusCode != HttpStatusCode.OK)
            {
                throw new Exception(rs.StatusCode.ToString() + ": " + rs.ReasonPhrase);
            }
            return(await rs.Content.ReadAsStringAsync());
        }
예제 #3
0
 public static void AddAuthHeader(CareviewApiConnection conn)
 {
     conn.HttpClient.DefaultRequestHeaders.Add("ApiKey", conn.ApiKey);
 }