Announcement Announcement Module
Collapse
No announcement yet.
OAuth2RestTemplate with post parameters? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 05:33 AM. Reason: Added "[SOLVED]" to title

  • #2
    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, 05:34 AM. Reason: Reformat code

    Comment

    Working...
    X