1. 程式人生 > >RestTemplate post表單,post寫入流

RestTemplate post表單,post寫入流

RestTemplate提交表單

HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);

MultiValueMap<String, String> map= new LinkedMultiValueMap<String, String>();
map.add("email", "[email protected]");

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);