예제 #1
0
        /*
         * Отправляет запрос
         */
        public async Task Send(Request request)
        {
            var requestMessage = new HttpRequestMessage(request.Metchod, request.Uri);

            if (request.Json != null)
            {
                requestMessage.Content = new StringContent(request.Json, encoding, mediaType);
            }

            if (request.AccessToken != null)
            {
                requestMessage.Headers.Add("Authorization", "token " + request.AccessToken);
            }

            request.SendDateTime = DateTime.Now;

            var responseMessage = await httpClient.SendAsync(requestMessage);

            var statusCode = responseMessage.StatusCode;

            var stringResponse = await responseMessage.Content.ReadAsStringAsync();

            var responseDateTime = DateTime.Now;

            request.AddResponse(responseDateTime, statusCode, stringResponse);

            if (bool.Parse(setting.GetValue("Debug")) == true)
            {
                loger.Write(request);
            }

            return;
        }