Using Java to supply username and password to login to a web site

Discussion in 'Java' started by Amit, Oct 17, 2003.

  1. Amit

    Amit Guest

    Using Java, I want to supply my username and password to login to a
    web site and manipulate the data on that site. Any suggestions?

    Let me know if you need more information.

    Thanks,
    Amit.
     
    Amit, Oct 17, 2003
    #1
    1. Advertising

  2. Amit

    Paul Lutus Guest

    Amit wrote:

    > Using Java, I want to supply my username and password to login to a
    > web site and manipulate the data on that site. Any suggestions?


    Yes. I would try computer programming in Java to solve this problem.

    What reply did you expect to such a bread inquiry, with no posted code or
    details?

    > Let me know if you need more information.


    Let me know when you realize how one posts about a matter such as this.

    --
    Paul Lutus
    http://www.arachnoid.com
     
    Paul Lutus, Oct 17, 2003
    #2
    1. Advertising

  3. Amit

    Chris Smith Guest

    Amit wrote:
    > Using Java, I want to supply my username and password to login to a
    > web site and manipulate the data on that site. Any suggestions?


    Can you provide more information about the web server? Is it expecting
    a form login? HTTP basic authentication? HTTP digest authentication?
    If it's not form login, then you can send an unauthenticated request,
    and get the type of authentication required back from the response
    headers. Form login is not designed to be accessible to machines, and
    requires human intelligence to figure it out from scratch, so you'd need
    to build in some knowledge (particularly, the names of the various
    fields).

    Incidentally, if you want to do the HTTP auth bit in a long-term
    maintainable way, I'd take a good strong look at HttpClient from Jakarta
    Commons and abandon URLConnection immediately (assuming you were looking
    at it in the first place).

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Oct 17, 2003
    #3
  4. Amit

    Amit Guest

    Chris Smith <> wrote in message news:<4.net>...
    > Amit wrote:
    > > Using Java, I want to supply my username and password to login to a
    > > web site and manipulate the data on that site. Any suggestions?

    >
    > Can you provide more information about the web server? Is it expecting
    > a form login? HTTP basic authentication? HTTP digest authentication?
    > If it's not form login, then you can send an unauthenticated request,
    > and get the type of authentication required back from the response
    > headers. Form login is not designed to be accessible to machines, and
    > requires human intelligence to figure it out from scratch, so you'd need
    > to build in some knowledge (particularly, the names of the various
    > fields).


    Chris, Thanks for the reply.

    What I am trying to do is to retrieve and save a page from a website.
    The website has a login page which is a form. When I type the url for
    any page, it returns the login page. i want to send the username and
    password using my Java program, so that it will return the actual
    page, rather than the redirected login page. Is it possible to submit
    the login form and then access the required page.
    >
    > Incidentally, if you want to do the HTTP auth bit in a long-term
    > maintainable way, I'd take a good strong look at HttpClient from Jakarta
    > Commons and abandon URLConnection immediately (assuming you were looking
    > at it in the first place).
     
    Amit, Oct 20, 2003
    #4
  5. Amit

    Chris Smith Guest

    Amit wrote:
    > What I am trying to do is to retrieve and save a page from a website.
    > The website has a login page which is a form. When I type the url for
    > any page, it returns the login page. i want to send the username and
    > password using my Java program, so that it will return the actual
    > page, rather than the redirected login page. Is it possible to submit
    > the login form and then access the required page.


    Okay, you need to first examine the login page, and find out some things
    about it:

    1. What is the name of the form field used for the username?
    2. What is the name of the form field used for the password?
    3. What is the URL used to submit the form (the "action")?
    4. What HTTP "method" is used to submit the form?
    5. Are there any extra form parameters expected by the server?

    Once you know this, you can build an appropriate HTTP request to
    simulate the form submission. Once you've submitted the form, chances
    are you need to handle cookies to actually remain logged in to the
    server. For *all* of this stuff (from building form parameters into an
    HTTP request to maintaining state with cookies), Jakarta Commons
    HttpClient will make your life much easier.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Oct 20, 2003
    #5
  6. Amit

    Amit Guest

    Chris, Thanks for your help, I had a look at Jakarta Commons
    HttpClient, it looks like it has what I need. I think it should work.
    Thanks again for your help.

    Amit.

    Chris Smith <> wrote in message news:<4.net>...
    > Amit wrote:
    > > What I am trying to do is to retrieve and save a page from a website.
    > > The website has a login page which is a form. When I type the url for
    > > any page, it returns the login page. i want to send the username and
    > > password using my Java program, so that it will return the actual
    > > page, rather than the redirected login page. Is it possible to submit
    > > the login form and then access the required page.

    >
    > Okay, you need to first examine the login page, and find out some things
    > about it:
    >
    > 1. What is the name of the form field used for the username?
    > 2. What is the name of the form field used for the password?
    > 3. What is the URL used to submit the form (the "action")?
    > 4. What HTTP "method" is used to submit the form?
    > 5. Are there any extra form parameters expected by the server?
    >
    > Once you know this, you can build an appropriate HTTP request to
    > simulate the form submission. Once you've submitted the form, chances
    > are you need to handle cookies to actually remain logged in to the
    > server. For *all* of this stuff (from building form parameters into an
    > HTTP request to maintaining state with cookies), Jakarta Commons
    > HttpClient will make your life much easier.
     
    Amit, Oct 21, 2003
    #6
  7. Amit

    hiren339in

    Joined:
    Nov 11, 2007
    Messages:
    1
    Hi Chris
    I saw the site and found it useful.If u have a sample could u please send it sos that I could test it on a url.
     
    hiren339in, Nov 11, 2007
    #7
  8. Amit

    anurahim

    Joined:
    Oct 17, 2008
    Messages:
    1
    Can I have some sample code using org.apache.http for submitting the username, password and some other parameters the server needs to login to a website from another site
     
    anurahim, Oct 17, 2008
    #8
  9. Amit

    Priyank

    Joined:
    Oct 13, 2011
    Messages:
    1
    I want to move a bit ahead.
    Acutally, on daily basis, I have to open an internal website,loginto that, navigate toa
    link/page,export an excel sheet and do processing.Can I go ahead to automate the same
    through Java Program.
    [Note : I can't directly access Database for that excel sheet data]
     
    Priyank, Oct 13, 2011
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arjen
    Replies:
    2
    Views:
    4,233
    Joe Fallon
    Apr 18, 2004
  2. Winista
    Replies:
    3
    Views:
    7,535
    blackstaronline.net
    Feb 21, 2006
  3. Rickard
    Replies:
    2
    Views:
    169
  4. zigzagdna
    Replies:
    7
    Views:
    493
    zigzagdna
    Feb 18, 2012
  5. Replies:
    4
    Views:
    203
    praveen kandala
    Oct 27, 2007
Loading...

Share This Page