title: Why is my Java program is hanging when trying to get a token from the Twitch.tv API with SSL?
body: <p>I am trying to authenticate with the Twitch.tv API and receive an access token, but I am having trouble being able to look at the body of the response.</p>
  
  <pre><code>public static void getToken(String body) {
  
      try {
      SSLSocketFactory sf = (SSLSocketFactory) SSLSocketFactory.getDefault();
      SSLSocket socket = (SSLSocket) sf.createSocket("api.twitch.tv", 443); 
  
      PrintWriter pw = new PrintWriter(socket.getOutputStream());
  
      pw.print("POST /kraken/oauth2/token HTTP/1.1\r\n");
      pw.print("Host: api.twitch.tv\r\n");
      pw.print("Content-Type: application/x-www-form-urlencoded\r\n");
      pw.print("Content-Length: 189\r\n");
      pw.print("Client-ID: [myClientIDHere]\r\n\r\n"); // Edited it out when posting online.
      pw.print(body);
      pw.flush();
  
      BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
      String line;
  
          while ((line = br.readLine()) != null) {
              System.out.println(line);              
          }
  
      br.close();
  
      } catch (IOException e) {
          e.printStackTrace();           
      }
  
  }
  </code></pre>
  
  <p>This is my code thus far. The output I get is: </p>
  
  <pre><code>HTTP/1.1 400 Bad Request
  Accept-Ranges: bytes
  Access-Control-Allow-Headers: 
  Access-Control-Allow-Methods: 
  Access-Control-Allow-Origin: *
  Age: 0
  Cache-Control: no-cache, no-store, must-revalidate
  Content-Type: application/json; charset=utf-8
  Date: Sat, 05 Nov 2016 07:22:35 GMT
  Pragma: no-cache
  Server: nginx
  Set-Cookie: unique_id=92143f722dd21b4e; domain=.twitch.tv; path=/; expires=Thu, 05-Nov-2026 07:22:35 GMT
  Set-Cookie: _twitch_session_id=8c5ec350cad83ea4150e1dc05be029f3; domain=.twitch.tv; path=/; expires=Sat, 05-Nov-2016 19:22:35 GMT; secure; HttpOnly
  Status: 400 Bad Request
  Vary: Accept-Encoding
  Via: 1.1 varnish
  X-Frame-Options: SAMEORIGIN
  X-MH-Cache: rails-varnish-api-aws-0538d8f099256d673; M
  X-Request-Id: 6f6355698a19e94058d35af2df918adb
  X-UA-Compatible: IE=Edge,chrome=1
  X-Varnish: 3967202340
  Content-Length: 75
  Connection: keep-alive
  </code></pre>
  
  <p>However, it will just hang after that and not give me anymore. Because of this, I can't debug why I am getting the bad request. Does anyone have any ideas as to why this is? (This is my first time posting, sorry if any formatting is improper).</p>
  
  <p>Thank you.</p>