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

3
  • you're setting a response header, but using a request header reserved word? Commented Jun 5, 2019 at 15:27
  • 1
    the api im working with requires the If-Match to be put in the header for the PUT Commented Jun 5, 2019 at 15:31
  • ok, don't set it on the content tho, set it on the parent Commented Jun 5, 2019 at 15:32

1 Answer 1

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");
    }
    // ...
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.