title: How to send headers and body using Jersey POST request?
body: <p>I haven't been able to hit an API successfully. I need to pass three values in the body of the POST request and a header: <code>"Content-Type":"application/x-www-form-urlencoded"</code>. </p>
  
  <p>I'm getting a 400 status, along with this:
   <code>Content-Type=[application/json;charset=UTF-8]</code>, can someone point me in the right direction here?</p>
  
  <pre><code>    Client client = ClientBuilder.newClient(); 
      WebTarget webTarget = client.target(REST_URI).path("dummy/dummy"); // REST_URI is a constant containing the URL
  
      // Create body content
      String json = Json.createObjectBuilder()
              .add("grant_type", "password")
                .add("username", USERNAME) // USERNAME/PASSWORD are constants
                .add("password", PASSWORD)
              .build()
              .toString();
  
  
      Response response = webTarget.request(MediaType.APPLICATION_FORM_URLENCODED)
              //.header("Content-Type", "application/x-www-form-urlencoded")
              .accept(MediaType.APPLICATION_FORM_URLENCODED)
              .post(Entity.entity(json, MediaType.APPLICATION_JSON));
  </code></pre>