title: Download file using REST API
body: <p>I am trying to call a REST API using Java client.</p>
  
  <p>The Rest API <a href="https://api.gdc.cancer.gov/data" rel="nofollow noreferrer">https://api.gdc.cancer.gov/data</a> has files data.
  When I append file name to the URL (<a href="https://api.gdc.cancer.gov/data/556e5e3f-0ab9-4b6c-aa62-c42f6a6cf20c" rel="nofollow noreferrer">https://api.gdc.cancer.gov/data/556e5e3f-0ab9-4b6c-aa62-c42f6a6cf20c</a>) I can download the given file from using browser.</p>
  
  <p>here filename is <code>556e5e3f-0ab9-4b6c-aa62-c42f6a6cf20c</code>.</p>
  
  <p>can you please let me know,How can i achieve in this JAVA. The code I am using.</p>
  
  <pre><code>import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.io.OutputStreamWriter;
  import java.net.HttpURLConnection;
  import java.net.URL;
  import java.util.ArrayList;
  import java.util.List;
  
  public class DownloadFilesAPI {
      public DownloadFilesAPI() {
          super();
      }
  
      public static String sendPostRequest(String requestUrl) {
          StringBuffer jsonString = new StringBuffer();
          try {
              URL url = new URL(requestUrl);
              HttpURLConnection connection = (HttpURLConnection) url.openConnection();
              // connection.setRequestMethod("POST");
              //   connection.connect();
              //Get the response status of the Rest API
              //  int responsecode = connection.getResponseCode();
              //System.out.println("Response code is: " +responsecode);
              //connection.getResponseMessage();
              // System.out.println(connection.getResponseMessage());
  
              connection.setDoInput(true);
              connection.setDoOutput(true);
              connection.setRequestMethod("POST");
              connection.setRequestProperty("Accept", "application/json");
              connection.setRequestProperty("Content-Type", "application/json");
              //  System.out.println(connection.getResponseMessage());
              //  System.out.println( JsonPath.from(requestUrl));
              OutputStreamWriter writer = new 
              OutputStreamWriter(connection.getOutputStream());
              writer.write(requestUrl);
              writer.close(); 
              /* BufferedReader br = new BufferedReader(new 
              InputStreamReader(connection.getInputStream()));
  
              String line;
              while ((line = br.readLine()) != null) {
                  jsonString.append(line);
              }
              br.close(); */
              connection.disconnect();
          } catch (Exception e) {
              throw new RuntimeException(e.getMessage());
          }
          return jsonString.toString();
      }
  
      public static void main(String[] args) {
          List&lt;String&gt; values = new ArrayList&lt;&gt;();
          // values.add("556e5e3f-0ab9-4b6c-aa62-c42f6a6cf20c");
          String requestUrl = "https://api.gdc.cancer.gov/data/556e5e3f-0ab9-4b6c-aa62-c42f6a6cf20c";
          sendPostRequest(requestUrl);
      }
      private static String preparePayload(List&lt;String&gt; values) {
      StringBuilder sb = new StringBuilder();
      for (String value : values) {
          sb.append("\"" + value + "\",");
      }
      String Requiredvalue = sb.toString().substring(0, sb.toString().length() - 1);
      return "{ \"ids\":[" + Requiredvalue + "] } } }";
      } 
  }
  </code></pre>