title: Robospice: Sending JSON data inside HTTP request body
body: <p>I need to send a <strong>POST HTTP request</strong> using Robospice for Android that will have data in the following format:</p>
  
  <blockquote>
    <p>Content-Type: application/json </p>
    
    <p>{'var1':'var1val','telNumber':'var2val'}</p>
  </blockquote>
  
  <p>There may be other HTTP headers inside but this is the only header required by the server - I've tested it with a simple HelloWorld request that doesn't require any specific objects in the body.</p>
  
  <p>The problem is that <strong>I can't send request body in the right format</strong>. I'm doing everything according the <a href="https://github.com/octo-online/robospice/wiki/Starter-Guide" rel="nofollow">Robospice tutorial</a>.</p>
  
  <p><strong><code>loadDataFromNetwork() method</code></strong></p>
  
  <pre><code>public T loadDataFromNetwork() throws Exception { // I'm making generic requests, T is a class representing given request
      Uri.Builder uriBuilder = Uri.parse(mUrl).buildUpon(); // mURL is just a full URL, including the method (just HTTP, not HTTPS)
      MultiValueMap&lt;String, String&gt; body = new LinkedMultiValueMap&lt;String, String&gt;();
      for (NameValuePair nvp : mPostParams) { // From the constructor: mPostParams = new ArrayList&lt;NameValuePair&gt;();
          body.add(nvp.getName(), nvp.getValue());
      }
  
      HttpEntity&lt;?&gt; requestEntity = new HttpEntity&lt;Object&gt;(body, mHttpHeaders);
      RestTemplate restTemplate = new RestTemplate();
  
      ResponseEntity&lt;T&gt; responseEntity = getRestTemplate().exchange(
              uriBuilder.build().toString(), HttpMethod.POST, requestEntity,
              mClazz);
      return responseEntity.getBody();
  }
  </code></pre>
  
  <p><strong><code>createRestTemplate()</code> in the <code>JsonSpiceService</code> class (which extends SpringAndroidSpiceService)</strong> </p>
  
  <pre><code>public RestTemplate createRestTemplate() {
      RestTemplate restTemplate = new RestTemplate(true);
  
      MappingJacksonHttpMessageConverter jsonConverter = new MappingJacksonHttpMessageConverter();
      FormHttpMessageConverter formHttpMessageConverter = new
      FormHttpMessageConverter();
      StringHttpMessageConverter stringHttpMessageConverter = new StringHttpMessageConverter();
      final List&lt;HttpMessageConverter&lt;?&gt;&gt; listHttpMessageConverters = restTemplate
              .getMessageConverters();
  
      setTimeout(restTemplate);
  
      listHttpMessageConverters.add(jsonConverter);
      listHttpMessageConverters.add(formHttpMessageConverter);
      listHttpMessageConverters.add(stringHttpMessageConverter);
      restTemplate.setMessageConverters(listHttpMessageConverters);
      return restTemplate;
  }
  </code></pre>
  
  <p>Doing it this way, I keep getting <code>500 Internal Server Error</code> and I am pretty sure it is related to format of the body. Is there any way of getting a <strong>raw</strong> HTTP request (not the <code>toString()</code> version of some methods just a raw request)? What else can I be doing wrong - can it be about encoding of the body?</p>
  
  <p>Note that I was testing the very same request with both Chrome app for sending REST requests and <code>curl</code> (worked fine).</p>