title: Making PUT request with JSON data using HttpURLConnection is not working
body: <p>I'm trying to make PUT request with JSON data using <code>HttpURLConnection</code> in Java. The way I do it doesn't work. I get no errors so I don't know what the problem is.</p>
  
  <pre><code>public static void main(String[] args) {
  
          URL url;
          try {
              url = new URL("http://fltspc.itu.dk/widget/515318fe17450f312b00153d/");
              HttpURLConnection hurl = (HttpURLConnection) url.openConnection();
              hurl.setRequestMethod("PUT");
              hurl.setDoOutput(true);
              hurl.setRequestProperty("Content-Type", "application/json");
              hurl.setRequestProperty("Accept", "application/json");
  
              String payload = "{'pos':{'left':45,'top':45}}";
  
              OutputStreamWriter osw = new OutputStreamWriter(hurl.getOutputStream());
              osw.write(payload);
              osw.flush();
              osw.close();
          } catch (MalformedURLException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>And here is the request I'm actually trying to make:</p>
  
  <p><img src="https://i.stack.imgur.com/My6fj.png" alt="Screenshot from Chrome Developer Tools"></p>
  
  <p>I was already making GET requests to the resource within the same app and it worked fine. I would be very grateful for all tips on how can I debug that or how can I try to do it some other way. So far I tried only using <code>OutputStream</code> instead of <code>OutputStreamWriter</code> but it doesn't work neither.  </p>