Example #1
0
 public async Task<IResponse> GetAsync(string url, Action<IRequest> prepareRequest)
 {
     var cts = new CancellationTokenSource();
     var handler = new DefaultHttpHandler(prepareRequest, cts.Cancel);
     var client = new HttpClient(handler);
     HttpResponseMessage responseMessage = await client.GetAsync(url, cts.Token);
     return new HttpResponseMessageWrapper(responseMessage);
 }
Example #2
0
        public async Task<IResponse> PostAsync(string url, Action<IRequest> prepareRequest, Dictionary<string, string> postData)
        {
            var cts = new CancellationTokenSource();
            var handler = new DefaultHttpHandler(prepareRequest, cts.Cancel);
            var client = new HttpClient(handler);

            HttpContent content = null;
            if (postData == null)
            {
                content = new StringContent(String.Empty);
            }
            else
            {
                content = new FormUrlEncodedContent(postData);
            }

            HttpResponseMessage responseMessage = await client.PostAsync(url, content, cts.Token);
            return new HttpResponseMessageWrapper(responseMessage);
        }
Example #3
0
        public async Task<IResponse> PostAsync(string url, Action<IRequest> prepareRequest, Dictionary<string, string> postData)
        {
            var cts = new CancellationTokenSource();
            var handler = new DefaultHttpHandler(prepareRequest, cts.Cancel);
            var client = new HttpClient(handler);
            var req = new HttpRequestMessage(HttpMethod.Post, url);

            if (postData == null)
            {
                req.Content = new StringContent(String.Empty);
            }
            else
            {
                req.Content = new FormUrlEncodedContent(postData);
            }

            HttpResponseMessage responseMessage = await client.SendAsync(req, HttpCompletionOption.ResponseHeadersRead, cts.Token);
            return new HttpResponseMessageWrapper(responseMessage);
        }