title: File download from url using HttpURLConnection |HTTP 400 if file name contain space
body: <p>I'm trying to download the files from url(soap request) using http connection, and below is my code, while executing i'm getting http = 400, because of file Name contain space <code>(ac abc.pdf)</code></p>
  
  <pre><code>        String downloadFileName = "ac abc.pdf";
          String saveDir = "D:/download";
  
          String baseUrl = "abc.com/AttachmentDownload?Filename=";
          URL url = new URL(baseUrl + downloadFileName);
          HttpURLConnection connection = (HttpURLConnection) url
                  .openConnection();
          connection.setReadTimeout(60 * 1000);
          connection.setConnectTimeout(60 * 1000);
  
          connection.setRequestMethod("POST");
          connection.setRequestProperty("Content-Type", "application/octet-stream");
          connection.setRequestProperty("SOAPAction", url.toString());
  
          String userCredentials = "user:pass";
          connection.setRequestProperty("Authorization", userCredentials);
  
          connection.setDoInput(true);
          connection.setDoOutput(true);
  
          int responseCode = connection.getResponseCode();
  
          if (responseCode == HttpURLConnection.HTTP_OK) {
  
              try (InputStream inputStream = connection.getInputStream()) {
                  String saveFilePath = saveDir + downloadFileName;
  
                  try (FileOutputStream outputStream = new FileOutputStream(saveFilePath)) {
                      int bytesRead = -1;
                      byte[] buffer = new byte[BUFFER_SIZE];
                      while ((bytesRead = inputStream.read(buffer)) != -1) {
                          outputStream.write(buffer, 0, bytesRead);
                      }
                  }
              }
  </code></pre>
  
  <p>while executing the above code getting the below output</p>
  
  <pre><code>responsecode400
  response messageBad Request
  No file to download. Server replied HTTP code: 400
  </code></pre>
  
  <p>let me know how can we format the url with the above situation</p>