Downloading from a password protected site

Is there a way to download information/files from a password protected site via java. Surf3rb0y
[109 byte] By [surf3rb0ya] at [2007-10-3 2:34:52]
# 1
Yup, you have to supply an authentication header. Look up the http protocol, because I don't have the exact spec to hand. Basically you have to take username:password, base 64 encode them and stick them in as part of an additional header.
malcolmmca at 2007-7-14 19:33:47 > top of Java-index,Java Essentials,Java Programming...
# 2

Or you could use this:

import java.net.Authenticator;

import java.net.PasswordAuthentication;

import java.net.URL;

import java.util.Scanner;

/**

* @since August 11, 2006, 10:52 AM

* @author Ian Schneider

*/

public class TestAuthenticator {

public static void main(String[] args) throws Exception {

String site = args[0];

final String name = args[1];

final String pass = args[2];

URL url = new URL(site);

Authenticator.setDefault(new Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication(name,pass.toCharArray());

}

});

System.out.println(new Scanner(url.openStream()).useDelimiter("\\z").next());

}

}

IanSchneidera at 2007-7-14 19:33:47 > top of Java-index,Java Essentials,Java Programming...
# 3

Ok thanks that part works but how do i make it grap the whole page? i get like the top portion and im assuming that the useDelimiter has something to do with that.

what i want to do exactly is save that file to my computer. Basicly copying the site that im connecting to or better yet leaving it in memory to be parsed. I want to grab some fields and print them to screen.

Thanks for the help

surf3rb0ya at 2007-7-14 19:33:47 > top of Java-index,Java Essentials,Java Programming...