Peter,
I was using the following code to connect to secure site , also the code
is a little old , it may not work out of the box , but atleast you'll get an
idea , may be you could modify it to work for your requirement.The files
imported are from JSSE jar
Hope that helps
Santosh
import java.net.*;
import java.io.*;
import java.util.Date;
import java.util.StringTokenizer;
import java.util.*;
import javax.net.*;
import javax.net.ssl.*;
import javax.security.cert.*;
import java.security.*;
import com.sun.net.ssl.*;
public class connURL implements ContentHandlerFactory
{
public ContentHandler createContentHandler(String mimetype)
{
return this.createContentHandler(mimetype);
}
public static void main(String args[])
{(String
if (args.length < 1)
{
System.err.println
("usage: java copyURL URL [LocalFile]");
System.exit(1);
}
try
{
// Set Authenticator
String userID = "userid";
String password = "password";
Authenticator.setDefault(new Authenticator(userID, password));
// Set Properties
System.setProperty("java.protocol.handler.pkgs",
"com.sun.net.ssl.internal.www.protocol");
Security.addProvider(new
com.sun.net.ssl.internal.ssl.Provider());
//Security.addProvider(new Provider());
System.out.println("Opening connection:\n" + '[' + args[0] +
']');
URL url = new URL(args[0]);
System.out.println("Opening connection to " + args[0] + "...");
URLConnection urlC = url.openConnection();
InputStream is = url.openStream();
// Print info about resource
System.out.print("Copying resource (type: " + urlC.getContentType());
Date date=new Date(urlC.getLastModified());
System.out.println(", modified on: " + date.toLocaleString() +
")...");
System.out.flush();
FileOutputStream fos=null;
if (args.length < 2)
{
String localFile=null;
// Get only file name
StringTokenizer st=new StringTokenizer(url.getFile(), "/");
while (st.hasMoreTokens())
localFile=st.nextToken();
fos = new FileOutputStream(localFile);
}
else
fos = new FileOutputStream(args[1]);
int oneChar, count=0;
while ((oneChar=is.read()) != -1)
{
fos.write(oneChar);
count++;
}
is.close();
fos.close();
System.out.println(count + " byte(s) copied");
}
catch (MalformedURLException e)
{ System.err.println(e.toString()); }
catch (IOException e)
{ System.err.println(e.toString()); }
}
}
"Norr, Peter" <[EMAIL PROTECTED]> on 10/10/2000 02:57:04 PM
Please respond to A mailing list about Java Server Pages specification and
reference <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED]
cc: (bcc: Santosh Daryani/IT/Aon Consulting)
Subject: URL Connection
How do I open a URL connection to a site that has basic authentication on?
I have the user name and password!!
Pete
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets