添加新的标题“ 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");
}
抛出:
Misused header name. Make sure request headers are used with HttpRequestMessage, response headers with HttpResponseMessage, and content headers with HttpContent objects.
我可以添加其他任何标头
答案 0 :(得分:1)
编辑:
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");
}
// ...
}