title: How do I convert this curl request to Apache HttpClient java code?
body: <p>I'm trying to send this in java:</p>
  <pre><code>curl -H &quot;Content-Type:application/json&quot; -XPOST 'http://www.example.com/foo' -d '{&quot;rootURL&quot;: &quot;http://www.subway.com&quot;}'
  </code></pre>
  <p>Here's the code I have:</p>
  <pre><code>    HttpClient client = new DefaultHttpClient();
      HttpPost post = new HttpPost(&quot;http://www.example.com/foo&quot;);
  
      post.setHeader(&quot;Content-Type&quot;, &quot;application/json&quot;);
  
      List&lt;NameValuePair&gt; urlParameters = new ArrayList&lt;NameValuePair&gt;();
      urlParameters.add(new BasicNameValuePair(&quot;rootURL&quot;, &quot;http://www.subway.com&quot;));
      post.setEntity(new UrlEncodedFormEntity(urlParameters));
      client.execute(post);
  </code></pre>
  <p>but I'm getting a 400 error:</p>
  <pre><code>Unexpected character ('r' (code 98)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: org.apache.catalina.connector.CoyoteInputStream@a18ba7b; line: 1, column: 2]
  </code></pre>
  <p>If I change this line:</p>
  <pre><code>urlParameters.add(new BasicNameValuePair(&quot;rootURL&quot;, &quot;http://www.subway.com&quot;));
  </code></pre>
  <p>to</p>
  <pre><code>urlParameters.add(new BasicNameValuePair(&quot;bootURL&quot;, &quot;http://www.subway.com&quot;));
  </code></pre>
  <p>I get the following error:</p>
  <pre><code>Unexpected character ('b' (code 98)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: org.apache.catalina.connector.CoyoteInputStream@a18ba7b; line: 1, column: 2]
  </code></pre>
  <p>Does anyone know what the problem is?</p>