apache http client send url encoded post request
<p>I have a dropwizard service in whitch i implemented a post request who consumes APPLICATION_FORM_URLENCODED media type and uses @FormParam annotation</p>

<p>Then in my client i'm using Apache HttpClient to make a post request like this:</p>

<pre><code>public void sendPost(String path, JsonObject params) throws Exception {

                String url = "http://" + TS_API_HOST + ":" + TS_API_PORT + "/" + path;

                CloseableHttpClient httpClient = HttpClients.createDefault();
                HttpPost httpPost = new HttpPost(url);
                httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
                List&lt;NameValuePair&gt; nvps = new ArrayList&lt;NameValuePair&gt;();

                Iterator&lt;String&gt; keys = params.keySet().iterator();
                while(keys.hasNext()){
                    String currentKey = keys.next();
                    nvps.add(new BasicNameValuePair(currentKey, params.get(currentKey).toString()));
                }
                System.out.println(nvps.toString());
                httpPost.setEntity(new UrlEncodedFormEntity(nvps));

                CloseableHttpResponse response = httpClient.execute(httpPost);

                try {
                    System.out.println(response.getStatusLine());
                    HttpEntity entity2 = response.getEntity();
                    // do something useful with the response body
                    // and ensure it is fully consumed
                    EntityUtils.consume(entity2);
                } finally {
                    response.close();
                }

            }
</code></pre>

<p>The url and params I'm passing are correct but i keep getting 400 bad request as a response.</p>

<p>In Postman it works very well...</p>