title: how to send http post with json body and url params?
body: <p>I saw this <a href="http://www.baeldung.com/httpclient-post-http-request" rel="nofollow">tutorial</a>.</p>
  
  <pre><code>List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
  params.add(new BasicNameValuePair("username", "John"));
  params.add(new BasicNameValuePair("password", "pass"));
  httpPost.setEntity(new UrlEncodedFormEntity(params));
  </code></pre>
  
  <p>and</p>
  
  <pre><code>String json = "{"id":1,"name":"John"}";
  StringEntity entity = new StringEntity(json);
  httpPost.setEntity(entity);
  httpPost.setHeader("Accept", "application/json");
  httpPost.setHeader("Content-type", "application/json");
  </code></pre>
  
  <p>I want to send a POST http request with json in the body and url params</p>
  
  <p>If I follow the example in the tutorial,</p>
  
  <p>will the second <code>setEntity</code> override the first <code>setEntity</code> ?</p>
  
  <p>if so, how should I write this?</p>