RestTemplate post表单,post写入流

来源:互联网 发布:excel一列数据求和 编辑:程序博客网 时间:2024/05/16 02:22

RestTemplate提交表单

HttpHeaders headers = new HttpHeaders();headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);MultiValueMap<String, String> map= new LinkedMultiValueMap<String, String>();map.add("email", "first.last@example.com");HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);ResponseEntity<String> response = restTemplate.postForEntity( url, request , String.class );

RestTemplate写入流

String body = "{\"name\":"TestUser"}";String res = restTemplate.postForObject(url,body,String.class);
原创粉丝点击