*
The moose likes Servlets and the fly likes Need help with authentications Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Need help with authentications" Watch "Need help with authentications" New topic
Author

Need help with authentications

Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
Hi All,
Desparatly need some hlp here.. Any tips will be greatly appreciated. Did not get an answer anywhere else, so thought of posting in this forum..
I had posted related q's some time back.. Basically, I'm writing a java program to download a text file from the internet.. Its an https connection to a SSL 2.0 server
These were the first two hurdle.. I learnt to use JSSE to connect thru https but SSL 2.0 is not supported.. Then I got a third party package called ICE SSL/ ICE STORM BROWSER and using its jar files (they inherit from java.net), I was able to connect and download from SSL 2.0
Now, if an authentication box pops up, I can use the java.net.authenticator class to authenticate myself, right ? Can this class be used for html (form based) logins ?
The problem is that my url is, say, https://www.mc.com/rpps/cgi-bin/download.cgi?file.txt and I get the html of the download.cgi file (please login.. ) when I run my program.
Please help..
Any way I can authenticate myself to the site for this purpose ?
Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
Is there anyone out there.. ?? Can anyone hear me ... ???
Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
got it !!! got it !!! here is the answer just for the info.
StringBuffer sb = new StringBuffer();
sb.append( URLEncoder.encode("Name") + "=" );
sb.append( URLEncoder.encode(nameField.getText()) );
sb.append( "&" + URLEncoder.encode("Password") + "=" );
sb.append( URLEncoder.encode(passwordField.getText()) );
String formData = sb.toString();
try {
URL url = new URL( getParameter("postURL") );
HttpURLConnection urlcon = (HttpURLConnection)url.openConnection();
urlcon.setRequestMethod("POST");
urlcon.setRequestProperty("Content-type",
"application/x-www-form-urlencoded");
urlcon.setDoOutput(true);
urlcon.setDoInput(true);
PrintWriter pout = new PrintWriter( new OutputStreamWriter(
urlcon.getOutputStream(), "8859_1"), true );
pout.print( formData );
pout.flush();
// read results...
if ( urlcon.getResponseCode() != HttpURLConnection.HTTP_OK ) {
System.out.println("Bad post...");
return;
}
InputStream in = urlcon.getInputStream();
// ...
} catch (MalformedURLException e) {
System.out.println("Bad postURL");
} catch (IOException e2) {
System.out.println("I/O error: "+e2);
}
 
Don't get me started about those stupid light bulbs.
 
subject: Need help with authentications