title: HTTP POST request to JIRA using Java yields 400 bad request error, curl works fine
body: <p>So I'm trying to retrieve information about Jira issues through REST API using Java, however I keep getting the 400 error. I feel like there's something really stupid that I'm missing, can anyone help me find out what's wrong with this? EDIT: I realised that I'm not sending the username/password to Jira in the Java program, but I'm actually unsure how to do that... Help here would be great! Here is the code I have (company name edited):</p>
  
  <pre><code>import java.io.*;
  import java.net.*;
  import java.util.*;
  
  public class JiraConnector 
  {
      public static void main(String[] args)
      {
          try {
              //store necessary query information
              URL jiraURL = new URL("http://jira.somecompany.com/rest/api/2/search");
              String data = "'{\"jql\":\"project = PROJ\"}'";
  
              //establish connection and request properties
              HttpURLConnection connection = (HttpURLConnection)jiraURL.openConnection();
              connection.setRequestMethod("POST");
              connection.setRequestProperty("Accept", "*/*");
              connection.setRequestProperty("Content-Type", "application/json");
              connection.setDoOutput(true);
              connection.setDoInput(true);
  
              connection.connect();
  
              OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
              wr.write(data.toString());
              wr.flush();
              wr.close();
  
              Reader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
              for (int c; (c = in.read()) &gt;= 0; System.out.print((char)c));
  
          } catch (MalformedURLException e) {
              System.err.println("MalformedURLException: " + e.getMessage());
          } catch (java.net.UnknownServiceException e) {
              System.err.println("UnknownServiceException: " + e.getMessage());
          } catch (IOException e) {
              System.err.println("IOException: " + e.getMessage());
          }        
      }
  }
  </code></pre>
  
  <p>For the record, using this curl command works:</p>
  
  <pre><code>curl -D- -u- user:password -X POST -H "Content-Type: application/json" --data '{"jql:"project=PROF"}' "http://jira.somecompany.com/rest/api/2/search"
  </code></pre>