http body与header设置与获取

RestTemplate将参数放到body中


HttpHeaders headers = new HttpHeaders();

//MediaType.APPLICATION_JSON 也可写成"application/json"

headers.setContentType(MediaType.APPLICATION_JSON);

HttpEntity<Object> request = new HttpEntity<Object>("请求内容", headers);

//发送

restTemplate.postForObject(URL, request, String.class);


获得请求中body中的内容

BufferedReader br = request.getReader();

String header = reques.getHeader("header名字");


你可能感兴趣的:(http body与header设置与获取)