title: download file from url with authentication
body: <p>i have a secured url , if i open in browser, a pop up comes and i authenitcate with userid/password, then a pdf file is downloaded .</p>
  
  <p>I want this functionality in java. It should authenticate using proxy server/port and user details then download</p>
  
  <pre><code>URL server = new URL("http://some.site.url/download.aspx?client=xyz&amp;docid=1001");
  System.setProperty("https.proxyUser", userName);
  System.setProperty("https.proxyPassword", password);
  
  System.setProperty("https.proxyHost",proxy);
  System.setProperty("https.proxyPort",port);
  
  URLConnection connection = (URLConnection)server.openConnection();
  connection.connect();
  InputStream is = connection.getInputStream();
  
  //then i read this input stream and write to a pdf file in temporary folder
  </code></pre>
  
  <p>It gives me connection timeout error.</p>
  
  <p>Then i thought adding authentication </p>
  
  <pre><code>String authentication = "Basic " + new
  sun.misc.BASE64Encoder().encode("myuserid:mypassword".getBytes());
  connection.setRequestProperty("Proxy-Authorization", authentication);
  </code></pre>
  
  <p>Still doesnt work,</p>
  
  <p>Please let me know .</p>