Exemplo n.º 1
0
 private Task <HttpResponseMessage> GetAsync(HttpClientExRequest request)
 {
     return(ExecuteRequest(async(client) =>
     {
         SetHeaders(request, client);
         return await client.GetAsync(request.Url);
     }));
 }
Exemplo n.º 2
0
 private Task <HttpResponseMessage> PutAsync(HttpClientExRequest request)
 {
     return(ExecuteRequest(async(client) =>
     {
         var httpContent = GetHttpContent(request);
         SetHeaders(request, client);
         return await client.PutAsync(request.Url, httpContent);
     }));
 }
Exemplo n.º 3
0
        private StringContent GetHttpContent(HttpClientExRequest request)
        {
            if (request.Content == null)
            {
                return(null);
            }

            string contentAsText = request.Content.ToString();

            return(new StringContent(contentAsText, null, "application/json"));
        }
Exemplo n.º 4
0
        private void SetHeaders(HttpClientExRequest request, System.Net.Http.HttpClient client)
        {
            if (request.Headers == null)
            {
                return;
            }

            foreach (var header in request.Headers)
            {
                client.DefaultRequestHeaders.Add(header.Key, header.Value);
            }
        }
Exemplo n.º 5
0
 private Task <HttpResponseMessage> PatchAsync(HttpClientExRequest request)
 {
     return(ExecuteRequest(async(client) =>
     {
         SetHeaders(request, client);
         var req = new HttpRequestMessage
         {
             Content = GetHttpContent(request),
             Method = new HttpMethod(HttpRequestType.PATCH.ToString()),
             RequestUri = new Uri(request.Url)
         };
         return await client.SendAsync(req);
     }));
 }
Exemplo n.º 6
0
        public async Task <HttpResponseMessage> SendRequest(HttpClientExRequest request)
        {
            switch (request.RequestType)
            {
            case HttpRequestType.POST:
                return(await PostAsync(request));

            case HttpRequestType.GET:
                return(await GetAsync(request));

            case HttpRequestType.DELETE:
                return(await DeleteAsync(request));

            case HttpRequestType.PUT:
                return(await PutAsync(request));

            default:
                throw new InvalidOperationException($"RequestType '{request.RequestType}' not supported");
            }
        }