我使用DataContractJsonSerializer和StringContent将
JSON发送到Web服务:
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)
这会导致此Content-Type标头:
Content-Type: application/json; charset=utf-8
是否有可能离开字符集,只是有以下标题?
Content-Type: application/json
我没有在StringContent上看到这样做的重载.