Results 1 to 2 of 2
  1. #1
    -Scriptwriter is offline Member
    Join Date
    Jul 2014
    Rep Power

    Default Https Request Authentication failing even after setting the proxy

    i am trying to access an https request on a server and authenticating it after passing on username and passwork. I have even set up the proxy of the employer to get the request back as a zipped folder.

    I always get an error on: " InputStream reader = con.getInputStream();"

    Can be a proxy setting issue too but I am not sure why it should be.

    Is there a way to create a secure channel in java to connect to https or by any way the below code could be modified to connect it to the server?

    Code is as below:



    import se64;

    public class DownloadFile
    static final String kuser = "username"; // your account name
    static final String kpass = "password"; // your password for the account
    static class MyAuthenticator extends Authenticator
    public PasswordAuthentication getPasswordAuthentication()
    System.err.println("Feeding username and password for " +getRequestingScheme());
    return (new PasswordAuthentication(kuser, kpass.toCharArray()));
    public static void main(String[] args)
    * * Get a connection to the URL and start up
    * * a buffered reader.
    * */
    long startTime = System.currentTimeMillis();
    System.out.println("Connecting to SWIFTRef Data website...\n");
    System.setProperty("http.proxyHost", "abcdef");
    System.setProperty("http.proxyPort", "8080");
    Authenticator.setDefault(new MyAuthenticator());

    URL url = new URL("");

    System.out.println("Establishing connection...");
    HttpsURLConnection con = (HttpsURLConnection)url.openConnection();

    System.out.println("Establishing connection...2");
    InputStream reader = con.getInputStream();
    System.out.println("Establishing connection...3");
    * * Setup a buffered file writer to write
    * * out what we read from the website.
    * */
    FileOutputStream writer = new FileOutputStream("");
    byte[] buffer = new byte[153600];
    int totalBytesRead = 0;
    int bytesRead = 0;
    System.out.println("Reading ZIP file 150KB blocks at a time.\n");
    while ((bytesRead = > 0)
    writer.write(buffer, 0, bytesRead);
    buffer = new byte[153600];
    totalBytesRead += bytesRead;
    long endTime = System.currentTimeMillis();
    System.out.println("Done. " + (new Integer(totalBytesRead).toString()) + " bytes read (" + (new Long(endTime - startTime).toString()) + " millseconds).\n");
    catch (MalformedURLException e)
    catch (IOException e)

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

    Default Re: Https Request Authentication failing even after setting the proxy

    When posting code please wrap it in code tags in order to retain the formatting.

    If you are getting an error then you'll also probably want to post the full exception and stack trace for it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. How to post HTTPS request
    By dror in forum Networking
    Replies: 1
    Last Post: 07-29-2012, 01:34 PM
  2. Https and authentication
    By vinaykutsa in forum Networking
    Replies: 0
    Last Post: 03-10-2011, 04:48 AM
  3. connection with authentication proxy
    By rioz in forum Networking
    Replies: 6
    Last Post: 02-15-2011, 02:05 AM
  4. Proxy authentication using HttpClient 4.0.3
    By Jsharma in forum Advanced Java
    Replies: 0
    Last Post: 01-21-2011, 04:33 AM
  5. How redirect a request to https
    By vns955 in forum Web Frameworks
    Replies: 1
    Last Post: 11-12-2009, 04:26 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts