Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

Muralidhar Gandepalli
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!