HttpEntity

public class HttpEntity<T>extends Object

Represents an HTTP request or response entity, consisting of headers and body.

HttpEntity 代表一个request请求或者响应,包含header和body,就包含头和体。

Typically used in combination with the RestTemplate, like so:

 HttpHeaders headers = new HttpHeaders();
 headers.setContentType(MediaType.TEXT_PLAIN);
 HttpEntity<String> entity = new HttpEntity<String>(helloWorld, headers);
 URI location = template.postForLocation("http://example.com", entity);
public class RestTemplate extends InterceptingHttpAccessorimplements RestOperations

另外对于spring RestTemplate 的说明。

Spring's central class for synchronous client-side HTTP access. It simplifies communication with HTTP servers, and enforces RESTful principles. It handles HTTP connections, leaving application code to provide URLs (with possible template variables) and extract results.

The main entry points of this template are the methods named after the six main HTTP methods:

or

 HttpEntity<String> entity = template.getForEntity("http://example.com", String.class);
 String body = entity.getBody();
 MediaType contentType = entity.getHeaders().getContentType();

Can also be used in Spring MVC, as a return value from a @Controller method:

 @RequestMapping("/handle")
 public HttpEntity<String> handle() {
   HttpHeaders responseHeaders = new HttpHeaders();
   responseHeaders.set("MyResponseHeader", "MyValue");
   return new HttpEntity<String>("Hello World", responseHeaders);
 }


转载于:https://my.oschina.net/u/2308739/blog/477636

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值