RestTemplate post表單,post寫入流
阿新 • • 發佈:2019-02-17
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);