I use DataContractJsonSerializer
and StringContent
to send JSON to a web service:
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Employee));
MemoryStream ms = new MemoryStream();
serializer.WriteObject(ms, employee);
ms.Position = 0;
StreamReader sr = new StreamReader(ms);
StringContent jsonContent = new StringContent(sr.ReadToEnd(),
System.Text.Encoding.UTF8, "application/json");
// later I do HttpClient.PostAsync(uri, jsonContent)
This results in this Content-Type header:
Content-Type: application/json; charset=utf-8
Is it possible to leave off the charset and just have the following header?
Content-Type: application/json
I don't see an overload on StringContent
which does this.