2 Replies Latest reply: Sep 28, 2006 5:43 PM by 807569 RSS

    How to add a header line to a URL?

    807569
      I have written an application which connects to a web page and extract some information from it.

      I use something similar the following code to get this done.

      URL url = new URL("http://www.google.ca");
      System.out.println("created URL");
      url.openStream();
      System.out.println("opened stream");
      // reads the contents of the web page here

      The web page that I�m connecting to has recently been made password protected.
      Now I�m required to include the following header line to my request in order to connect to it.

      Authorization: Basic <base64-encoded-username:password>

      Could somebody please tell me how to extend the above code to request the same web page with this particular header line?

      Note that my application is a regular Java app. I cannot and am not using J2EE stuff here.

      Thanks in advance!