title: How do I properly send a POST in HTTPS through Java?
body: <p>I'm writing a mod for a game in Java to check to see if the player has voted using a server methods to get the Steam ID. I can't get a good response from what I'm seeing. Every response is an IOException which I've had print out "Invalid Response Code".</p>
  
  <p>I've tried implementing what I've seen in similar mods for https connections, but I am not getting anywhere with it.</p>
  
  <pre class="lang-java prettyprint-override"><code>try {
    HttpsURLConnection connection = (HttpsURLConnection) new URL(             "https://somewebsite.com/"
                  ).openConnection();
                  connection.setSSLSocketFactory(createTrustAllSocketFactory());
  
                  int responseCode = connection.getResponseCode();
                  if (responseCode != 200) throw new IOException("Invalid response code.");
  
                  InputStream in = connection.getInputStream();
  
                  ByteArrayOutputStream stringBuffer = new ByteArrayOutputStream();
                  byte[] buffer = new byte[256];
                  int len = 0;
                  while (len != -1) {
                      stringBuffer.write(buffer, 0, len);
                      len = in.read(buffer);
                  }
  
                  String result = new String(stringBuffer.toByteArray(), StandardCharsets.UTF_8);
                  if (result.equals("1")) {
                      try {
                          performer.addMoney(MonetaryConstants.COIN_COPPER * 5);
                          performer.getCommunicator().sendNormalServerMessage("Thanks for voting! Your rewards have been added to your bank.");
                      } catch (IOException ex) {
                          performer.getCommunicator().sendAlertServerMessage("Failed to add reward. Please submit a support ticket.");
                          ex.printStackTrace();
                      }
                  }
  
  private static SSLSocketFactory createTrustAllSocketFactory() throws IOException {
                  try {
                      SSLContext ctx = SSLContext.getInstance("TLS");
                      TrustManager[] trustManagers = {
                              new X509TrustManager() {
                                  @Override
                                  public void checkClientTrusted(X509Certificate[] chain, String authType) {
                                      /* empty */
                                  }
  
                                  @Override
                                  public void checkServerTrusted(X509Certificate[] chain, String authType) {
                                      /* empty */
                                  }
  
                                  @Override
                                  public X509Certificate[] getAcceptedIssuers() {
                                      return new X509Certificate[0];
                                  }
                              }
                      };
                      ctx.init(null, trustManagers, null);
                      return ctx.getSocketFactory();
                  } catch (GeneralSecurityException ex) {
                      throw new IOException(ex);
                  }
              }
  </code></pre>
  
  <p>The expectation is that when the command is issued in-game, the server will call the external site with the player's steam ID and generate either a 0 or 1 based on if they have voted.</p>
  
  <p>Actual is getting a bad response code.</p>