类 HttpEntity<T>

java.lang.Object
cn.taketoday.http.HttpEntity<T>
类型参数:
T - the body type
直接已知子类:
MultipartBodyBuilder.PublisherEntity, RequestEntity, ResponseEntity

public class HttpEntity<T> extends Object
Represents an HTTP request or response entity, consisting of headers and body.

like so:


 HttpHeaders headers = HttpHeaders.create();
 headers.setContentType(MediaType.TEXT_PLAIN);
 HttpEntity<String> entity = new HttpEntity<>(helloWorld, headers);
 URI location = template.postForLocation("https://example.com", entity);
 
or

 HttpEntity<String> entity = template.getForEntity("https://example.com", String.class);
 String body = entity.getBody();
 MediaType contentType = entity.getHeaders().getContentType();
 
Can also be used in Web MVC, as a return value from a @Controller method:

 @RequestMapping("/handle")
 public HttpEntity<String> handle() {
   HttpHeaders responseHeaders = HttpHeaders.create();
   responseHeaders.set("MyResponseHeader", "MyValue");
   return new HttpEntity<>("Hello World", responseHeaders);
 }
 
从以下版本开始:
3.0 2020/12/6 17:10
作者:
Arjen Poutsma, Juergen Hoeller, Harry Yang
另请参阅:
  • 字段详细资料

    • EMPTY

      public static final HttpEntity<?> EMPTY
      The empty HttpEntity, with no body or headers.
    • headers

      private final HttpHeaders headers
    • body

      @Nullable private final T body
  • 构造器详细资料

    • HttpEntity

      protected HttpEntity()
      Create a new, empty HttpEntity.
    • HttpEntity

      public HttpEntity(T body)
      Create a new HttpEntity with the given body and no headers.
      参数:
      body - the entity body
    • HttpEntity

      public HttpEntity(cn.taketoday.util.MultiValueMap<String,String> headers)
      Create a new HttpEntity with the given headers and no body.
      参数:
      headers - the entity headers
    • HttpEntity

      public HttpEntity(@Nullable T body, @Nullable cn.taketoday.util.MultiValueMap<String,String> headers)
      Create a new HttpEntity with the given body and headers.
      参数:
      body - the entity body
      headers - the entity headers
  • 方法详细资料

    • getHeaders

      public HttpHeaders getHeaders()
      Returns the headers of this entity.
    • getBody

      @Nullable public T getBody()
      Returns the body of this entity.
    • hasBody

      public boolean hasBody()
      Indicates whether this entity has a body.
    • equals

      public boolean equals(Object other)
      覆盖:
      equals 在类中 Object
    • hashCode

      public int hashCode()
      覆盖:
      hashCode 在类中 Object
    • toString

      public String toString()
      覆盖:
      toString 在类中 Object