title: How do I login and download a file from a https web page from Java?
body: <p>I have to login into a https web page and download a file using Java.
  I know all the URLs beforehand:</p>
  
  <pre><code>baseURL = // a https URL;
  urlMap = new HashMap&lt;String, URL&gt;();
  urlMap.put("login", new URL(baseURL, "exec.asp?login=username&amp;pass=XPTO"));
  urlMap.put("logout", new URL(baseURL, "exec.asp?exec.asp?page=999"));
  urlMap.put("file", new URL(baseURL, "exec.asp?file=111"));
  </code></pre>
  
  <p>If I try all these links in a web browser like firefox, they work.</p>
  
  <p>Now when I do:</p>
  
  <pre><code>urlConnection = urlMap.get("login").openConnection();
  urlConnection.connect();
  BufferedReader in = new BufferedReader(
      new InputStreamReader(urlConnection.getInputStream()));
  String inputLine;
  while ((inputLine = in.readLine()) != null)
      System.out.println(inputLine);
  in.close();
  </code></pre>
  
  <p>I just get back the login page HTML again, and I cannot proceed to file download.</p>
  
  <p>Thanks!</p>