示例#1
0
        public async Task PostAsync(string url, object msg)
        {
            using (var client = HttpClientFactory.Create(HttpHandlers.ToArray()))
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ChannelAccessToken);
                var res = await client.PostAsync($"{UrlPrefix}{url}", msg, Formatter).ConfigureAwait(false);

                if (!res.IsSuccessStatusCode)
                {
                    var body = await res.Content.ReadAsAsync <ErrorResponse>().ConfigureAwait(false);

                    throw new LineException(body.Message, body);
                }
            }
        }
示例#2
0
        public async Task <TResponse> GetAsync <TResponse>(string url)
        {
            using (var client = HttpClientFactory.Create(HttpHandlers.ToArray()))
            {
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", ChannelAccessToken);
                var res = await client.GetAsync($"{UrlPrefix}{url}").ConfigureAwait(false);

                if (!res.IsSuccessStatusCode)
                {
                    var body = await res.Content.ReadAsAsync <ErrorResponse>();

                    throw new LineException(body.Message, body);
                }

                return(JsonConvert.DeserializeObject <TResponse>(await res.Content.ReadAsStringAsync().ConfigureAwait(false)));
            }
        }