title: HTTP PUT Request to Bitbucket API
body: <p>I want to develop a java library for bitbucket issues API access.<br>
  I've already asked a question about <a href="https://stackoverflow.com/questions/6354928/java-httpurlconnection-content-length-computation">the computation of the HTTP Content-Length header</a>, but this question is specifically about the <a href="http://confluence.atlassian.com/display/BBDEV/Issues#Issues-Updatinganissue" rel="nofollow noreferrer">Bitbucket API</a> and the process of updating an issue (since every other request works well).</p>
  
  <p>The following code doesn't work, giving a <code>411 Length Required</code> error.<br>
  But even more confusing: In the documentation, you are told to use <code>PUT</code> request method. If you "forget" to specify that, status code changes to <code>200 OK</code>, but leaving the issue unchanged.</p>
  
  <pre><code>public class PutTest {
      public static void main(String[] args) throws Exception {
          URL u = new URL("https://api.bitbucket.org/1.0/repositories/myname/myproject/issues/1/?title=hello+world");
          HttpURLConnection c = (HttpURLConnection) u.openConnection();
          c.addRequestProperty("Authorization", "Basic "+Base64.encodeToString("user:password".getBytes(), false));
          c.addRequestProperty("Content-Length", String.valueOf(u.getQuery().getBytes("UTF-8").length));
          c.setRequestMethod("PUT");
          c.connect();
          System.out.println(c.getResponseCode()+" "+c.getResponseMessage());
      }
  }
  </code></pre>