[lug] Off topic: java form-based authentication in a client program
Jim Buzbee
jbuzbee at nyx.net
Wed Aug 30 11:00:36 MDT 2006
On Wed, 30 Aug 2006, Michael J. Hammel wrote:
> A browser-based login works just fine. But I'm having problems finding
> information on how to programmatically login from the Java client.
Hi Michael - I'm not sure this is what you want, but here's a java
fragment that accesses a password-protected web site. It relies on
another Base64Converter class that can be found on-line.
Jim
---
import java.awt.*;
import java.io.*;
import java.net.*;
public class Install
{
public static void fetch(String address, String pw)
throws MalformedURLException, IOException
{
String line;
URL url = new URL(address);
URLConnection uc = url.openConnection();
String encoding = Base64Converter.encode("demo:" + pw );
uc.setRequestProperty("Authorization", "Basic " + encoding);
InputStream content = (InputStream)uc.getInputStream();
BufferedReader in = new BufferedReader(new
InputStreamReader(content));
while ((line = in.readLine()) != null) { }
}
public static void main(String[] args)
throws MalformedURLException, IOException
{
fetch( args[0], args[1]) ;
}
}
--------------------------------------------------------------------------------
Jim Buzbee "I was gratified to be able to
jbuzbee at nyx.net answer promptly, and I did. I
http://batbox.org said I didn't know." Mark Twain
More information about the LUG
mailing list