File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Sockets and Internet Protocols and the fly likes Logging in to a site programmatically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Logging in to a site programmatically" Watch "Logging in to a site programmatically" New topic
Author

Logging in to a site programmatically

mano ranjan
Ranch Hand

Joined: Jul 12, 2007
Posts: 102
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
Marshal

Joined: Mar 22, 2005
Posts: 39576
    
  27
That depends on how the login on this site is implemented. Is this a web site using some kind of HTTP authentication?


Ping & DNS - updated with new look and Ping home screen widget
mano ranjan
Ranch Hand

Joined: Jul 12, 2007
Posts: 102
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

Joined: Mar 06, 2001
Posts: 13459

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

Joined: Apr 14, 2004
Posts: 10336

Not an advanced question. Moving...


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

This really has nothing to do with servlets either.

Moving to our sockets and internet protocols forum.
Sorry for all the bouncing.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
mano ranjan
Ranch Hand

Joined: Jul 12, 2007
Posts: 102
Hi
i need to login a site using programmatically is it possible to do legally if yes how to do???

thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39576
    
  27
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

    Joined: Jul 12, 2007
    Posts: 102
    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
    Marshal

    Joined: Mar 22, 2005
    Posts: 39576
        
      27
    Please post the code and the HTML login form you're trying to emulate.
    mano ranjan
    Ranch Hand

    Joined: Jul 12, 2007
    Posts: 102
    HI
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 39576
        
      27
    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

    Joined: Jul 12, 2007
    Posts: 102
    HI
    Is this jWebUnit is http testing tool ???
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 39576
        
      27
    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

    Joined: Jul 12, 2007
    Posts: 102
    Hi
    thanks for your reply . but iam not able to download from here

    thanks
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 39576
        
      27
    The download works fine for me.
     
    jQuery in Action, 2nd edition
     
    subject: Logging in to a site programmatically
     
    Similar Threads
    valiveru mock test
    Sample tests for IBM 286
    Job Search Site
    Is This site hackered ???
    WA #1.....word association