2

adding new header "If-Match"

 using (HttpContent content = new StringContent(serializedObject))
        {
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            content.Headers.Remove("If-Match");
            content.Headers.Add("If-Match", "XXXXXXXXXX");
        }

throws :

Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.

i can add any other headers fine

Samw
  • 128
  • 1
  • 10

1 Answers1

1

edited:

using(var request = new HttpRequestMessage(HttpMethod.Put, new Uri(url))) {
    request.Headers.Remove("If-Match");
    request.Headers.TryAddWithoutValidation("If-Match", "XXXXXXXXXX");
    using (HttpContent content = new StringContent(serializedObject))
    {
        content.Headers.Remove("Content-Type");
        content.Headers.Add("Content-Type", "application/json");
    }
    // ...
}
user326608
  • 2,210
  • 1
  • 26
  • 33