Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Logging in to a site programmatically

 
mano ranjan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
My requirement is to login a site with user name and password by using java program.Is this possible ??? if yes suggestions please...

thanks
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That depends on how the login on this site is implemented. Is this a web site using some kind of HTTP authentication?
 
mano ranjan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Yes the site which iam trying to login uses https authentication and uses post method in action.any tips how should i proceed???

thanks
[ July 17, 2007: Message edited by: mano ranjan ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You still haven't provided much in the way of details. Apache provides a HTTP library that makes logging in and session management much easier.

In HTTP, Basic Authentication is a doddle, form based authentication is also pretty easy.

Anything else?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not an advanced question. Moving...
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This really has nothing to do with servlets either.

Moving to our sockets and internet protocols forum.
Sorry for all the bouncing.
 
mano ranjan
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
i need to login a site using programmatically is it possible to do legally if yes how to do???

thanks
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by mano ranjan:
i need to login a site using programmatically is it possible to do legally if yes how to do?


Several things come to mind:
  • If this is a web app, then you can use the java.net.HttpUrlConnection class, or the Jakarta Commons HttpClient library to do this. More comfortable would be to use a package like jWebUnit, which works at the HTML level; login forms aren't different than other HTML forms.
  • Why are you concerned about the legality? Is this is a web site you're not supposed to access?
  • If this is a web site meant for people to use, then just doing the login programmatically isn't going to help much, is it? What do you hope to do with the content of whichever page gets sent after you login?

  •  
    mano ranjan
    Ranch Hand
    Posts: 102
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    HI
    Its is a site where i must login to it and read the data's from a particular
    page.Yes iam using URLConnection for this purpose but after providing the username and password by post action . iam getting the inputstream of this url
    after reading that url i still get the old login page data . but not the logged in page page.(i.e its not logged in i think).So how to login ???

    thanks
     
    Ulf Dittmer
    Rancher
    Posts: 42968
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Please post the code and the HTML login form you're trying to emulate.
     
    mano ranjan
    Ranch Hand
    Posts: 102
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    HI
     
    Ulf Dittmer
    Rancher
    Posts: 42968
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    This code retrieves the login page, yet there's nothing in it that would submit the login form back to the server (and then read what the server sends back after that).

    If the web session involves more than just a page or two, it will be simpler to use a library like jWebUnit, rather than working with on the HTTP level like this.
     
    mano ranjan
    Ranch Hand
    Posts: 102
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    HI
    Is this jWebUnit is http testing tool ???
     
    Ulf Dittmer
    Rancher
    Posts: 42968
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Originally posted by mano ranjan:
    Is this jWebUnit is http testing tool ???


    It is, but it can just as well be used outside of a testing context. It is very useful for accessing web sites programmatically.
     
    mano ranjan
    Ranch Hand
    Posts: 102
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi
    thanks for your reply . but iam not able to download from here

    thanks
     
    Ulf Dittmer
    Rancher
    Posts: 42968
    73
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The download works fine for me.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic