title: Spring RestTemplate PostforObject: Unsupported Media Type
body: <p>I'm trying to execute a RESTful web service, however, when I send the request, HttpClientErrorException occurs with "415 Unsupported Media Type" as the message.</p>
  
  <p>This is the code for the service call:</p>
  
  <pre><code>MultiValueMap&lt;String, String&gt; request = new LinkedMultiValueMap&lt;String, String&gt;();
  request.add(val1, "xxxxx");
  request.add(val2, "************");
  request.add(val3, "xxx");
  request.add("type", "AUTHENTICATE");
  
  String response = restTemplate.postForObject(url, request, String.class);
  System.out.println(response.toString());
  </code></pre>
  
  <p>The restTemplate is wired from an applicationContext.xml, with a FormHttpMessageConverter as its messageConverter.</p>
  
  <pre><code>&lt;bean id="restTemplate" class="org.springframework.web.client.RestTemplate"&gt;
  &lt;constructor-arg name="requestFactory" ref="httpClientFactory"/&gt;
  &lt;property name="messageConverters"&gt;
      &lt;list&gt;
          &lt;bean class="org.springframework.http.converter.FormHttpMessageConverter"/&gt;
  &lt;/list&gt;
  &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="httpClientFactory" class="org.springframework.http.client.CommonsClientHttpRequestFactory"&gt;
      &lt;constructor-arg ref="httpClient"/&gt;
  &lt;/bean&gt;
  &lt;bean id="httpClientParams" class="org.apache.commons.httpclient.params.HttpClientParams"&gt;
      &lt;property name="authenticationPreemptive" value="true"/&gt;
      &lt;property name="connectionManagerClass"
                    value="org.apache.commons.httpclient.MultiThreadedHttpConnectionManager"/&gt;
  &lt;/bean&gt;
  &lt;bean id="httpClient" class="org.apache.commons.httpclient.HttpClient"&gt;
      &lt;constructor-arg ref="httpClientParams"/&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p>This is the exception that occurs:</p>
  
  <pre><code>Exception in thread "main" org.springframework.web.client.HttpClientErrorException: 415 Unsupported Media Type
      at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:76)
      at org.springframework.web.client.RestTemplate.handleResponseError(RestTemplate.java:486)
      at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:443)
      at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:401)
      at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:279)
      at ph.com.smart.drawbridge.commons.diameter.DiameterClient.post(DiameterClient.java:21)
  </code></pre>
  
  <p>Any ideas?</p>