title: .net httpclient encapsulation "one or more errors" occured
body: <p>A problem was encountered when I was trying to encapsulate a .net http client rest helper, I just don't know where is the problem, would someone be so kind to offer a hand.
  helper class below:</p>
  
  <pre><code>public class RestHelper
  {
      private string BuildApiUriFromRequest(HttpRequestBase request)
      {
          return request.Url.ToString();
      }
      private static IEnumerable&lt;KeyValuePair&lt;string, string&gt;&gt; GetFromForm(NameValueCollection form)
      {
          if (form == null) return null;
          Dictionary&lt;string, string&gt; nameValueCollection = new Dictionary&lt;string, string&gt;();
          form.AllKeys.ToList().ForEach(key =&gt;
          {
              nameValueCollection.Add(key, form[key]);
          });
          return nameValueCollection;
      }
      public static void Get(string url, Action&lt;string&gt; customise)
      {
          RestMethod(url, null, customise, (httpClient, requestUrl, httpContent) =&gt;
          {
              return httpClient.GetAsync(requestUrl);
          });
      }
      public static void Post(string url, NameValueCollection form, Action&lt;string&gt; customise)
      {
          RestMethod(url, form, customise, (httpClient, requestUrl, httpContent) =&gt; { return httpClient.PostAsync(requestUrl, httpContent); });
      }
      public static void Put(string url, NameValueCollection form, Action&lt;string&gt; customise)
      {
          RestMethod(url, form, customise, (httpClient, requestUrl, httpContent) =&gt; { return httpClient.PutAsync(requestUrl, httpContent); });
      }
      public static void Delete(string url, Action&lt;string&gt; customise)
      {
          RestMethod(url, null, customise, (httpClient, requestUrl, httpContent) =&gt; { return httpClient.DeleteAsync(requestUrl); });
      }
      public static void RestMethod(HttpRequestBase request, Action&lt;string&gt; customise)
      {
          Get(request.Url.ToString(), customise);
      }
      public static void RestMethod(string url, NameValueCollection form, Action&lt;string&gt; customise, Func&lt;HttpClient, string, HttpContent, Task&lt;HttpResponseMessage&gt;&gt; getResponseHttpMessage)
      {
          var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip };
          using (var client = new HttpClient(handler))
          {
              FormUrlEncodedContent content = null;
              if (form != null)
              {
                  IEnumerable&lt;KeyValuePair&lt;string, string&gt;&gt;        nameValueCollection = GetFromForm(form);
                  content = new FormUrlEncodedContent(nameValueCollection);
              }
              HandleResult(client, url, content, customise, getResponseHttpMessage);
          }
      }
      private static void HandleResult(HttpClient client, string url, FormUrlEncodedContent content, Action&lt;string&gt; customise, Func&lt;HttpClient, string, HttpContent, Task&lt;HttpResponseMessage&gt;&gt; getResponseHttpMessage)
      {
          getResponseHttpMessage(client, url, content).ContinueWith(httpResponseMessage =&gt;
          {
              try
              {
                  httpResponseMessage.Result.EnsureSuccessStatusCode();
                  httpResponseMessage.Result.Content.ReadAsStringAsync().ContinueWith(readTask =&gt;
                  {
                      customise(readTask.Result);
                  });
              }
              catch (Exception ex)
              {
                  customise(ex.Message);
              }
          });
      }
  }
  </code></pre>
  
  <p>I was testing get method when I meet with some problem, it seemed to be a delegate exception, but the compiler was not showing more exception details,
  then I tried using a raw httpclient with continue-with method, and the request returned the correct result json string. Is it something about the httphandler that I was wrong about? using a pure http client may be ok? but I want it to be more slim.. </p>