title: Access to confluence REST api from java
body: <p>I´m trying to get any correct response from Confluence REST API, but I´m still getting IOException saying server is answering with 500 status code. Here is the code I´m using:</p>
  
  <pre><code>String test = executePost("http://&lt;server&gt;/rest/api/content/");
  
  public static String executePost(String targetURL) 
  {
    HttpURLConnection connection = null;
  
    try 
    {
      //Create connection
      URL url = new URL(targetURL);
      connection = (HttpURLConnection) url.openConnection();
      connection.setRequestMethod("POST");
      connection.setRequestProperty("Content-Type",
            "application/json; charset=utf-8");
  
      String name = "admin";
      String password = "admin";
  
      String authString = name + ":" + password;
      String encodedString = Base64.getEncoder().encodeToString(authString.getBytes());
  
      connection.setRequestProperty("Authorization", "Basic " + encodedString);     
  
      connection.setUseCaches(false);
      connection.setDoOutput(true);
  
      //Send request
      DataOutputStream wr = new DataOutputStream(
            connection.getOutputStream());
      wr.close();
  
      //Get Response  
      InputStream is = connection.getInputStream();
      BufferedReader rd = new BufferedReader(new InputStreamReader(is));
      StringBuffer response = new StringBuffer();
      String line;
      while ((line = rd.readLine()) != null) 
      {
        response.append(line);
        response.append('\r');
      }
      rd.close();
      return response.toString();
    } 
    catch (IOException e) 
    {
      e.printStackTrace();
      return null;
    } 
    finally 
    {
      if (connection != null) 
        connection.disconnect();
    }
  }
  </code></pre>
  
  <p>The error I´m getting back says:</p>
  
  <pre><code>java.io.IOException: Server returned HTTP response code: 500 for URL: http://&lt;server&gt;/rest/api/content/
  </code></pre>
  
  <p>When i try to send the request over curl with same credentials, I´m getting expected response, which have to mean, I´m missing something in my java code, but I can´t find out what.</p>