如何为HttpClient请求设置内容类型标头?
Content-Type
HttpClient
Content-Type
using (var httpClient = new HttpClient()){ httpClient.BaseAddress = new Uri("http://example.com/"); httpClient.DefaultRequestHeaders.Add("Accept", "application/json"); httpClient.DefaultRequestHeaders.Add("Content-Type", "application/json"); // ...}
Accept
Content-Type
误用头名。确保将请求标头与 HttpRequestMessage
,响应头与 HttpResponseMessage
,以及内容标头与 HttpContent
物品。
Content-Type
HttpClient
心有法竹