title: .net HttpClient with custom JsonConverter
body: <p>I'm using .NET's HttpClient to make requests to a WebAPI that returns some JSON data that requires a little bit of custom deserialization on the client's side.  For this I've made my own <code>JsonConverter</code>, but I can't figure out how to have the <code>ReadAsAsync&lt;T&gt;</code> method pick up the existence of the converter.  </p>
  
  <p>I've solved my problem for now by using <code>ReadAsStringAsync</code> to read the response, then passing that string in to <code>JsonConvert.DeserializeObject</code>, but it seems like there should be a more elegant solution.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>public PrefsResponse GetAllPrefs(string sid) {
      HttpClient client = CreateHttpClient(null, sid);
      var response = client.GetAsync("api/sites/" + sid).Result;
  
      // TODO : find a way to hook custom converters to this...
      // return response.Content.ReadAsAsync&lt;PrefsResponse&gt;().Result;
  
      var stringResult = response.Content.ReadAsStringAsync().Result;
  
      return JsonConvert.DeserializeObject&lt;PrefsResponse&gt;(stringResult, new PrefClassJsonConverter());
  }
  </code></pre>
  
  <p>Is this the best I can do, or is there some more elegant way?</p>
  
  <p>Here's where I'm creating the HttpClient also, if that's where I need to hook it up:</p>
  
  <pre><code>        private HttpClient CreateHttpClient(CommandContext ctx, string sid) {
          var cookies = new CookieContainer();
  
          var handler = new HttpClientHandler {
              CookieContainer = cookies,
              UseCookies = true,
              UseDefaultCredentials = false
          };
  
          // Add identity cookies:
          if (ctx != null &amp;&amp; !ctx.UserExecuting.IsAnonymous) {
              string userName = String.Format("{0} ({1})", ctx.RequestingUser.UserName, ctx.UserExecuting.Key);
              cookies.Add(new Cookie(__userIdCookieName, userName));
              cookies.Add(new Cookie(__sidCookieName, sid));
              cookies.Add(new Cookie(__hashCookieName,
                                     GenerateHash(userName, Prefs.Instance.UrlPrefs.SharedSecret)));
          }
  
          var client = new HttpClient(handler) {
              BaseAddress = _prefServerBaseUrl
          };
  
          client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
  
  
          return client;
      }
  </code></pre>