How to enter the site through java?

I tried several ways to enter the site through java. I used watij, HTMLunit, etc., but due to the fact that he is not familiar with them, I can not log in successfully.

Can someone tell me in detail how to login through java

To be more specific, I want to log into ORKUT and want the page source page to appear after logging in.

+4
source share
4 answers

Your best chance of doing such things and surviving on a real network is Selenium-RC.

Basically, what you will do is remotely control your browser to do everything you can do manually (except for downloading files).

Many times I used this template:

  • Sign in with selenium
  • Take cookies
  • Continue to work with my favorite HTTP library.
+3
source

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

  • Do you need to provide username and password in HTTP headers (basic auth)?
  • Or do you need to fill out and submit a form containing your username and password?

For both, I would recommend commons-httpclient, although the latter approach to escaping is always useless for programmatic programming.

For basic authentication, check out the httpclient Authentication Guide .

To authenticate forms, you need to check the source of the HTML page to understand

  • Form url submitted
  • What parameter names to send are

For help on how to submit the form in httpclient, see the POST documentation .

The httpclient site also contains a basic tutorial .

+5
source

Why are you trying to log in through Java, why not just use cURL? Is there anything specific you are trying to accomplish?

0
source

Orkut uses Google authorization to log in. My suggestion is to use an HTTP debugger such as Fiddler to view traffic during login. There are probably cookies and redirects that you need to replicate.

At all,

  • Look at the login form, get the name and password field names and the action that the form sends to
  • Create a POST request for the action url and enter the name and password correctly (e.g. name = username & password = pwd)
  • Was this HTTPS (be sure to do it right)
  • If the response has a SET-COOKIE in the header, be sure to send this cookie to all subsequent requests
  • If the response is redirected, then do a GET to redirect, sending cookies if necessary
  • (keep looping at # 5 until you get a redirect)

The answer you get at the end of this is the source of the page.

Take a look at this:

http://code.google.com/apis/gdata/javadoc/com/google/gdata/client/http/AuthSubUtil.html http://code.google.com/p/apex-google-data/source/browse /trunk/google_data_toolkit/src/classes/AuthSubUtil.cls

Looks like a Google authentication code with their services.

0
source

All Articles