title: Spring RestTemplate POST Request with URL encoded data
body: <p>I'm new to Spring and trying to do a rest request with RestTemplate. The Java code should do the same as below curl command:</p>
  
  <pre><code>curl --data "name=feature&amp;color=#5843AD" --header "PRIVATE-TOKEN: xyz" "https://someserver.com/api/v3/projects/1/labels"
  </code></pre>
  
  <p>But the server rejects the RestTemplate with a <code>400 Bad Request</code></p>
  
  <pre><code>RestTemplate restTemplate = new RestTemplate();
  HttpHeaders headers = new HttpHeaders();
  headers.add("PRIVATE-TOKEN", "xyz");
  HttpEntity&lt;String&gt; entity = new HttpEntity&lt;String&gt;("name=feature&amp;color=#5843AD", headers);
  ResponseEntity&lt;LabelCreationResponse&gt; response = restTemplate.exchange("https://someserver.com/api/v3/projects/1/labels", HttpMethod.POST, entity, LabelCreationResponse.class);
  </code></pre>
  
  <p>Can somebody tell me what I'm doing wrong?</p>