Announcement Announcement Module
Collapse
No announcement yet.
Spring Android Resttemplate postforobject Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Android Resttemplate postforobject

    Hi all,

    I'm trying to use android spring rest template to do a post request. And i need to return the status code. This is my approach.

    <code>
    RestTemplate restTemplate = new RestTemplate();
    MultiValueMap mvm = new LinkedMultiValueMap();
    mvm.add("login", "100"); // and some more paramters
    String result = restTemplate.postForObject("http://localhost:8080/security_check", mvm, String.class);

    </code>

    But this approach doesn't work for me. It generates an error saying no suitable message converter found. And i need to know can i use the resttemplate to manage my sessions. I need to manage the session from the android client side.

    If any one come across android resttemplate post method and session management please help me. Any help would be greatly appreciated.
    Thanks in advance.

  • #2
    Re: Spring Android RestTemplate postForObject

    Did you assign message converters?

    Code:
    MultiValueMap<String, String> mvm = new LinkedMultiValueMap<String, String>();
    mvm.add("login", "100"); 
        	
    RestTemplate restTemplate = new RestTemplate();
        	
    List<HttpMessageConverter<?>> messageConverters = new ArrayList<HttpMessageConverter<?>>();
    messageConverters.add(new FormHttpMessageConverter());
    messageConverters.add(new StringHttpMessageConverter());
    restTemplate.setMessageConverters(messageConverters);
    		
    String result = restTemplate.postForObject("http://10.1.1.1:9998/security_check", mvm, String.class);
        	
    Log.d(TAG, "Result: [" + result + "]");
    I noticed that you used localhost. That will not work because the code considers your phone as localhost and it will only work if you have another process on your phone listening on 9998. You need to put an actual IP address or domain name in your url.

    Perry Hoekstra
    Last edited by dutchman_mn; Dec 6th, 2010, 01:32 PM. Reason: Added additional information

    Comment


    • #3
      Thanks dutchman. I will look into it.

      Comment

      Working...
      X