Try:
java.net.Authenticator.setDefault(new java.net.Authenticator() {
protected java.net.PasswordAuthentication getPasswordAuthentication() {
return new java.net.PasswordAuthentication("user",
"password".toCharArray());
}
});
URL url = new URL("http://hostname/path");
...
HTH,
Stan
-----Original Message-----
From: Scot Mcphee [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, September 10, 2002 1:10 AM
To: JDJList
Subject: [jdjlist] username/password in java.net.URL?
I am trying to put the username and password required by a server into the
java.net.URL class so I can get some data off a password protected server.
The URL class always returns a FileNotFound exception. There doesn't seem to
be any way to set the authentication information other than in the full URL
string as per the standard way;
http://user:password@hostname/path
the URL works great in either IE or Mozilla. However this code;
String location = "http://user:password@hostname/path";
URL url = new URL(location);
URLConnection urlC = url.openConnection();
urlC.connect();
always produces the exception;
java.io.FileNotFoundException: http://user:password@hostname/path
If I try this;
url.getAuthority();
it returns;
user:password@hostname
I've the various other separators in RFC2396 but all others return
"MalformedURLException". The individual components constructor of the URL
class doesn't include the authority info as a separate item. The JavaDoc has
a 'set' method but it's a protected member.
Does anyone have any idea how I can progress further? Do I have to subclass
it? Is there another technique?
thanks
scot.
___________________________________________
Scot Mcphee - Snr Developer
- (mobile) +61-412-957414
___________________________________________
Tigerex - http://www.tigerex.net
- (bus) +61-2-82593613
___________________________________________
To change your JDJList options, please visit:
http://www.sys-con.com/java/list.cfm
To change your JDJList options, please visit: http://www.sys-con.com/java/list.cfm