Issue
I would like to POST a JSON request using Flurl with the content header Content-Language specified. I already managed to set the content type (Content-Type) without any issues:
string response = await "https://jsonplaceholder.typicode.com/".AppendPathSegment("posts")
.WithHeaders(new { Content_Type = "application/json; charset=UTF-8" })
.PostJsonAsync(new { title = "bar", body = "foo", userId = 1 }).ReceiveString();
Console.WriteLine(response);
correctly returning:
{
"title": "bar",
"body": "foo",
"userId": 1,
"id": 102
}
However, trying to specify Content-Language in addition:
string response = await "https://jsonplaceholder.typicode.com/".AppendPathSegment("posts")
.WithHeaders(new { Content_Type = "application/json; charset=UTF-8", Content_Language = "en-US" })
.PostJsonAsync(new { title = "bar", body = "foo", userId = 1 }).ReceiveString();
Console.WriteLine(response);
breaks the code giving the error
Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.
I understand that content headers should be set on the content and not the request, however, after reading this answer (and this one) it seemed like there's no need to distinct request and content levels anymore with Flurl 2.0+.
Side note
The used API is a mock. I'm aware that using PostJsonAsync automatically sets the Content-Type header, however, for my use case, it will be set to application/vnd.api+json and therefore, needs to be specified explicitly.
Question
What am I doing wrong? Is there anything I do not understand about content headers?
What makes Content-Language any different from Content-Type when adding it to a request?