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

George Sexton gsexton at mhsoftware.com
Wed Aug 30 11:18:27 MDT 2006


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
>
>   

-- 
George Sexton
MH Software, Inc.
Voice: +1 303 438 9585
URL:   http://www.mhsoftware.com/




More information about the LUG mailing list