Java - HTTP Post Jira API - Bad Request
<p>I have this code to do a <code>HTTP Post</code> to a <strong>Jira</strong> URL (<code>https://xxxxxxx.atlassian.net/rest/api/2/issue/</code>):</p>

<pre><code>    Object jsonMessage = arg0.getMessage().getPayload();

    URL url = new URL(jiraUrl + jiraIssuePath);

    HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

    BASE64Encoder enc = new sun.misc.BASE64Encoder();
    String userpassword = jiraUsername + ":" + jiraPassword;
    String encodedAuthorization = enc.encode(userpassword.getBytes());
    conn.setDoOutput(true);
    conn.setDoInput(true);
    conn.setRequestProperty("Authorization", "Basic " + encodedAuthorization);
    conn.setRequestProperty("Content-Type", "application/json;charset=UTF-8");

    conn.setRequestMethod("POST");

    OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
    wr.write(jsonMessage.toString());
    wr.flush();

    StringBuilder sb = new StringBuilder();
    int HttpResult = conn.getResponseCode();
    if (HttpResult == HttpsURLConnection.HTTP_OK) {
        BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "utf-8"));
        String line = null;
        while ((line = br.readLine()) != null) {
            sb.append(line + "\n");
        }
        br.close();
        System.out.println("" + sb.toString());
    } else {
        System.out.println(conn.getResponseMessage());
    }
</code></pre>

<p>If I use a HTTP Get without JSON message it works fine, but if I use a POST sending a JSON message it return me this error:</p>

<blockquote>
  <p>java.io.IOException: Server returned HTTP response code: 400 for URL:
  <a href="https://xxxxxxx.atlassian.net/rest/api/2/issue/" rel="nofollow">https://xxxxxxx.atlassian.net/rest/api/2/issue/</a></p>
</blockquote>

<p>I use <strong>Postman App</strong> to check headers(<code>Content-Type</code> and <code>Authorization</code>) and body and with that App it create the issue in Jira.</p>

<p><strong>Added:</strong>
If I inspect the connection it has the parameter <code>Method</code> like <code>GET</code> instead of <code>POST</code>.</p>

<p>What can I be doing wrong?</p>