问题
HttpRequestMessage
Has Content.Headers and Headers
Why is that? when I google Http protocol online, I don't see anyone mentioning a content header and a normal header, there are only "headers"
回答1:
Unfortunately, the MSDN documentation for MVC, WebAPI and System.Net.Http are appaling. See HttpContentHeaders.ContentType Property:
Gets or sets {insert text here}.
Well-known content-specific headers are grouped under "content headers". It's just for convenience. There are headers like content-type
, content-length
, and so on, as seen in HttpContentHeaders Class:
- Public property Allow Gets {insert text here}.
- Public property ContentDisposition Gets or sets {insert text here}.
- Public property ContentEncoding Gets {insert text here}.
- Public property ContentLanguage Gets {insert text here}.
- Public property ContentLength Gets or sets {insert text here}.
- Public property ContentLocation Gets or sets {insert text here}.
- Public property ContentMD5 Gets or sets {insert text here}.
- Public property ContentRange Gets or sets {insert text here}.
- Public property ContentType Gets or sets {insert text here}.
- Public property Expires Gets or sets {insert text here}.
- Public property LastModified Gets or sets {insert text here}.
回答2:
From what I can tell, content headers come into play when you are dealing with MultipartContent or MultipartFormDataContent. The example in this blog post explicity applies a "Content-Type" header at the content level.
http://dotnetcodr.com/2013/01/10/how-to-post-a-multipart-http-message-to-a-web-service-in-c-and-handle-it-with-java/
来源:https://stackoverflow.com/questions/30508837/whats-the-difference-between-a-content-header-and-a-header