code: String getResponseEncoding(URLConnection connection) {
  
          String charset = null;
  
          String contentType = connection.getHeaderField("Content-Type");
          if (contentType != null) {
              for (String param : contentType.replace(" ", "").split(";")) {
                  if (param.startsWith("charset=")) {
                      charset = param.split("=", 2)[1];
                      break;
                  }
              }
          }
          return charset;
      }
docs: Determine the response encoding if specified
  
  @param connection The HTTP connection
  @return The response encoding as a string (taken from "Content-Type")