title: Why am I getting HTTP 400 bad request
body: <p>I am using an HTTP client (code copied from <a href="http://www.mkyong.com/java/apache-httpclient-examples/" rel="nofollow">http://www.mkyong.com/java/apache-httpclient-examples/</a>) to send post requests. I have been trying to use it with <a href="http://postcodes.io" rel="nofollow">http://postcodes.io</a> to look up a bulk of postcodes but failed. According to <a href="http://postcodes.io" rel="nofollow">http://postcodes.io</a> I should send a post request to <a href="http://api.postcodes.io/postcodes" rel="nofollow">http://api.postcodes.io/postcodes</a> in the following JSON form: <code>{"postcodes" : ["OX49 5NU", "M32 0JG", "NE30 1DP"]}</code> but I am always getting HTTP Response Code 400.
  I have included my code below. Please tell me what am I doing wrong?
  Thanks</p>
  
  <pre><code>private void sendPost() throws Exception {
  
      String url = "http://api.postcodes.io/postcodes";
      HttpClient client = HttpClientBuilder.create().build();
      HttpPost post = new HttpPost(url);
  
      List&lt;NameValuePair&gt; urlParameters = new ArrayList&lt;NameValuePair&gt;();
      urlParameters.add(new BasicNameValuePair("postcodes", "[\"OX49 5NU\", \"M32 0JG\", \"NE30 1DP\"]"));
      post.setEntity(new UrlEncodedFormEntity(urlParameters));
      HttpResponse response = client.execute(post);
  
      System.out.println("Response Code : " 
                  + response.getStatusLine().getStatusCode());
      System.out.println("Reason : " 
              + response.getStatusLine().getReasonPhrase());
      BufferedReader br = new BufferedReader(
              new InputStreamReader(response.getEntity().getContent()));
      StringBuffer result = new StringBuffer();
      String line = "";
      while ((line = br.readLine()) != null) {
          result.append(line);
      }
      br.close();
      System.out.println(result.toString());
  }
  </code></pre>