HTTP messages can carry a content entity associated with the request or response. Entities can be found in some requests and in some responses, as they are optional. Requests that use entities are referred to as entity enclosing requests. The HTTP specification defines two entity enclosing request methods: POST and PUT. Responses are usually expected to enclose a content entity. There are exceptions to this rule such as responses to HEAD method and 204 No Content, 304 Not Modified, 205 Reset Content responses.
HttpClient distinguishes three kinds of entities, depending on where their content originates:
streamed: The content is received from a stream, or generated on the fly. In particular, this category includes entities being received from HTTP responses. Streamed entities are generally not repeatable.
self-contained: The content is in memory or obtained by means that are independent from a connection or other entity. Self-contained entities are generally repeatable. This type of entities will be mostly used for entity enclosing HTTP requests.
wrapping: The content is obtained from another entity.
This distinction is important for connection management when streaming out content from an HTTP response. For request entities that are created by an application and only sent using HttpClient, the difference between streamed and self-contained is of little importance. In that case, it is suggested to consider non-repeatable entities as streamed, and those that are repeatable as self-contained.
HTTP訊息可以攜帶一個請求和響應的內容關聯實體。實體可以在一些請求和一些響應中找到,因為它們是可選的。使用實體的請求被稱為實體封閉請求。HTTP規範定義了兩種實體封裝要求方法:POST和PUT。響應通常預計將包含一個內容實體。有此規則的異常,如回應標頭方法和204沒有內容,304沒有修改,205複位內容響應。
根據其內容來源於哪裡: HttpClient區分三種實體,
流:內容是從流接收,或動態產生的。特別是,這一類包括實體接收從HTTP響應。流實體一般不可重複。
包含:該內容是在記憶體中,或通過與串連或其他實體獨立的方式獲得的。包含的實體通常是可重複的。這種類型的實體將主要用於實體封裝HTTP請求。
封裝:內容是從另一個實體獲得的。
這種區別對於串連管理時流出來的內容從一個HTTP響應是很重要的。這是由一個應用只發送使用HttpClient請求實體流和獨立之間的差異並不重要。在這種情況下,建議考慮非可重複的實體作為流,和那些是可重複的作為獨立的。