Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to login to a website through java?

I have tried several ways to login to a website through java. I have used watij, HTMLunit etc. but due to not so familiar with any of these, I am not able to login successfully.

Can anyone tell me in detail how to login through java

To be more specific, I want to login to the ORKUT and want the pagesource of the page that comes after login.

like image 667
Yatendra Avatar asked Mar 01 '23 07:03

Yatendra


1 Answers

The answer depends on how the website attempts to authenticate you:

  • Do you have to set a username and password in the HTTP headers (basic auth)?
  • Or do you have to fill out and submit a form containing the username and password?

For either I would recommend commons-httpclient, although the latter screen-scraping approach is always messy to do programatically.

For basic authentication, take a look at httpclient's Authentication Guide.

For forms authentication, you'll need to check the HTML source of the page to understand

  • The URL the form is submitted to
  • What the names of the parameters to submit are

For help on how to submit a form in httpclient, take a look at the documentation on the POST method.

The httpclient site also contains a basic tutorial.

like image 105
matt b Avatar answered Mar 07 '23 23:03

matt b