title: HttpClient.PutAsync - "Entity only allows writes with a JSON Content-Type header"
body: <p>I have a POST method that can post data perfectly. </p>
  
  <p>Looking at docs it seems a PATCH (or PUT) should look the exact same, just use <code>PutAsync</code> instead of <code>PostAsync</code>.</p>
  
  <p>Well doing just that I get the following error:</p>
  
  <pre><code>+       postResponse    {StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.NoWriteNoSeekStreamContent, Headers:
  {
    Cache-Control: private
    Date: Mon, 09 Oct 2017 12:19:28 GMT
    Transfer-Encoding: chunked
    request-id: 60370069-f7c4-421d-842e-b1ee8573c2c2
    client-request-id: 60370069-f7c4-421d-842e-b1ee8573c2c2
    x-ms-ags-diagnostic: {"ServerInfo":{"DataCenter":"North Europe","Slice":"SliceB","ScaleUnit":"002","Host":"AGSFE_IN_7","ADSiteName":"DUB"}}
    Duration: 3.2626
    Content-Type: application/json
  }}  System.Net.Http.HttpResponseMessage
  </code></pre>
  
  <p>And response: </p>
  
  <blockquote>
    <p>Entity only allows writes with a JSON Content-Type header</p>
  </blockquote>
  
  <p>And sure enough in the Error I can also see this:</p>
  
  <pre><code>ContentType {text/plain; charset=utf-8} System.Net.Http.Headers.MediaTypeHeaderValue
  </code></pre>
  
  <p>So the error makes sense, however, I do tell it to use JSON, and it work as intended in my POST-method with the same code:</p>
  
  <pre><code>public async Task UpdateToGraph(object UnSerializedContent, string relativeUrl)
  {
      string accessToken = await _tokenManager.GetAccessTokenAsync();
      HttpContent content = new StringContent(JsonConvert.SerializeObject(UnSerializedContent));
  
      Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
      Client.DefaultRequestHeaders.Add("ContentType", "application/json");
  
      string endpoint = "https://graph.microsoft.com/v1.0" + relativeUrl;
      var postResponse = Client.PutAsync(endpoint, content).Result;
  
      string serverResponse = postResponse.Content.ReadAsStringAsync().Result;
  }
  </code></pre>