File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Logging into a Site with out Using Browser.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Logging into a Site with out Using Browser...." Watch "Logging into a Site with out Using Browser...." New topic

Logging into a Site with out Using Browser....

Muralidhar Gandepalli

Joined: Apr 16, 2001
Posts: 15
Hi Iam need help with soem what unique situation ...and its like this
I want to save a particular url "" on my m/c, which I can do as follows - open a URLConnection, get the inputstream and then write it to the disk.
code :
//blha blha
URLConnection connection = url.openConnection();
InputStream stream = connection.getInputStream();
BufferedInputStream in = new BufferedInputStream(stream);
FileOutputStream file = new FileOutputStream("forum"+sId+".html");
BufferedOutputStream out = new BufferedOutputStream(file);

int i;
while ((i = != -1) {

Problem is, to access "", I need to login into the site. If I access the URL directly, I get redirected to the login page.

And all my code is run through a Stand alone Java progm.
Pour in your suggestion .....
Tx in advance!!
[ June 13, 2003: Message edited by: Muralidhar Gandepalli ]
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

I'm assuming you have the username and password available on the local machine?
You need to make an initial request that pretends to be the data submitted from the login page. When this page returns it will give you a session ID. Then you attach this session ID to subsequent addresses.
You'r going to have to look into some of the HTTP protocol. Login requests are usually POSTed, and the session ID is maintained as a Cookie in the request header.
It shouldn't be too dificult, but I don't have anything handy to help at the moment. Hopefully someone can post some code demonstrating POSTing via a URLConnection, stripping a Cookie, and sending a Cookie via another Connection?
peter greaves
Ranch Hand

Joined: Sep 27, 2002
Posts: 51
what david is basically saying is that you need to write a microbrowser that does "enough" to create the POST and do the networking. your code is really jsut using the transport layer - but you need to provide a skeletal implementation of the browser client (IOW a request generator and response handler) to do what you are asking for.

SJCP 1.2
I agree. Here's the link:
subject: Logging into a Site with out Using Browser....
It's not a secret anymore!