How to add a header line to a URL?

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抦 connecting to has recently been made password protected.

Now I抦 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!

[882 byte] By [Sudarshaa] at [2007-10-3 6:07:32]
# 1
try using the Commons httpclient: http://jakarta.apache.org/commons/httpclient/here's the authentication guide: http://jakarta.apache.org/commons/httpclient/authentication.html
syncroa at 2007-7-15 0:50:38 > top of Java-index,Java Essentials,Java Programming...
# 2
You can do it in just the standard JDK by getting an HttpURLConnection from the URL, and then using the setRequestProperty method.I don't know whether that's easier or harder than the HttpClient solution. My guess is that it's harder.
paulcwa at 2007-7-15 0:50:38 > top of Java-index,Java Essentials,Java Programming...