[lug] Off topic: java form-based authentication in a client program

mohadib mohadib at openactive.org
Wed Aug 30 14:55:36 MDT 2006


URLConnection is the best way , but you can also use
the JDIC browser. The benefit of this is you can leverage the
browser and javascript. You dont have to show the browser.

good luck,
jd

On Wed, 2006-08-30 at 11:18 -0600, George Sexton wrote:
> To continue along this vein, it would be necessary usually to catch the 
> Session ID cookie that comes back in the response, and submit it with 
> all subsequent requests.
> 
> Jim Buzbee wrote:
> > 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
> >
> > _______________________________________________
> > Web Page:  http://lug.boulder.co.us
> > Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> > Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
> >
> >   
> 




More information about the LUG mailing list