Skip to content

Instantly share code, notes, and snippets.

@sandipchitale
Last active September 12, 2018 19:49
Show Gist options
  • Save sandipchitale/9e3c45ad320757dcd0f12ed85ccb82e2 to your computer and use it in GitHub Desktop.
Save sandipchitale/9e3c45ad320757dcd0f12ed85ccb82e2 to your computer and use it in GitHub Desktop.
Post with RestTemplate
RestTemplate restTemplate = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
// add to map the form parameters
HttpEntity<MultiValueMap<String, String>> request = new HttpEntity<MultiValueMap<String, String>>(map, headers);
try {
restTemplate.postForEntity(url, request, String.class);
} catch (RestClientException e) {
handleRestClientException(e);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment