title: Server returned HTTP response code: 500 while posting FormData using java
body: <p>I am trying to post formData in java. I am getting 500 server error. In the API I am trying to call the name of the FormData parameter is template @FormDataParam("template")  </p>
  
  <p>Here I have shared my code snippet:</p>
  
  <pre><code>URL url = new URL(url);
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  byte[] data = formData.getBytes();
  connection.setDoInput(true);
  connection.setRequestProperty("Content-Type", "multipart/form-data");
  connection.setRequestMethod("POST");
  connection.setDoOutput(true);
  connection.connect();
  BufferedReader readData;
  try ( DataOutputStream writeData =
              new DataOutputStream(connection.getOutputStream())) {
  
      writeData.writeBytes("Content-Disposition: form-data; name=\""
          + "template" + "\""+ "\\r\\n");
      writeData.write(data);
      writeData.flush();
      readData = new BufferedReader(
                  new InputStreamReader(connection.getInputStream()));
      String line;
      while ((line = readData.readLine()) != null) {
          response.append(line);
      }
  }       
  </code></pre>