Results 1 to 2 of 2

Thread: OAuth2RestTemplate with post parameters?

  1. #1
    Join Date
    Sep 2011
    Posts
    3

    Default [SOLVED] OAuth2RestTemplate with post parameters?

    Hi,

    Is anyone able to help me with using the OAuth2RestTemplate with post parameters?

    I found a blog post at http://lkonopski.blogspot.com.au/2012/05/using-spring-resttemplate-with.html?m=1
    that shows how to do this with the RestTemplate:

    Code:
     HttpHeaders  headers = new HttpHeaders();
     headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
     HttpEntity req = new HttpEntity<>(urlEncodeYourParams(), headers);
     RestTemplate rest = new RestTemplate();
     ResponseEntity result = rest.postForEntity(address, req, String.class);
     System.out.println( result.getBody() );
    However I'm unsure what form the parameters need to take in the HttpEntity constructor.

    Is anyone able to offer any examples or suggestions?

    Many thanks in advance,
    Andrew.
    Last edited by am2605; Aug 10th, 2012 at 05:33 AM. Reason: Added "[SOLVED]" to title

  2. #2
    Join Date
    Sep 2011
    Posts
    3

    Default

    I have solved this after finding this StackOverflow post.

    The solution was:

    Code:
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
    
    MultiValueMap<String, String> map = new LinkedMultiValueMap<String, String>();
    map.add("name", "Andrew");
    
    HttpEntity<MultiValueMap<String, String>> req = new HttpEntity<MultiValueMap<String, String>>(map, headers);
    I assume to urlEncode parameters you'd just do them when you add them to the map?
    Last edited by am2605; Aug 10th, 2012 at 05:34 AM. Reason: Reformat code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •