title: How to remove charset=utf8 from Content-Type header generated by HttpClient.PostAsJsonAsync()?
body: <p>I have an issue with 
      HttpClient.PostAsJsonAsync()</p>
  
  <p>In addition to "application/json" in the "Content-Type" header the method also adds "charset=utf-8"</p>
  
  <p>so the header looks like this:</p>
  
  <p>Content-Type: application/json; charset=utf-8</p>
  
  <p>While ASP.NET WebAPI doesn't have any issue with this header, i've found that other WebAPIs I work against as a client don't accept request with this header, unless it's only application/json.</p>
  
  <p>Is there anyway to remove the "charset=utf-8" from Content-Type when using PostAsJsonAsync(), or should I use another method?</p>
  
  <p><strong>SOLUTION:</strong>
  Credits to Yishai!</p>
  
  <pre><code>using System.Net.Http.Headers;
  
  public class NoCharSetJsonMediaTypeFormatter : JsonMediaTypeFormatter
  {
     public override void SetDefaultContentHeaders(Type type, HttpContentHeaders headers, MediaTypeHeaderValue mediaType)
     {
         base.SetDefaultContentHeaders(type, headers, mediaType);
         headers.ContentType.CharSet = "";
     }
  }
  
  public static class HttpClientExtensions
  {
      public static async Task&lt;HttpResponseMessage&gt; PostAsJsonWithNoCharSetAsync&lt;T&gt;(this HttpClient client, string requestUri, T value, CancellationToken cancellationToken)
      {
          return await client.PostAsync(requestUri, value, new NoCharSetJsonMediaTypeFormatter(), cancellationToken);
      }
  
      public static async Task&lt;HttpResponseMessage&gt; PostAsJsonWithNoCharSetAsync&lt;T&gt;(this HttpClient client, string requestUri, T value)
      {
          return await client.PostAsync(requestUri, value, new NoCharSetJsonMediaTypeFormatter());
      }
  }
  </code></pre>