For some reason this code will not let me into the website when I use the correct login information. The System.out.println
posts the code of the login page, indicating my code did not work. Can someone tell me what I'm forgetting or what's wrong with it?
public void connect() {
try {
Connection.Response loginForm = Jsoup.connect("https://www.capitaliq.com/CIQDotNet/Login.aspx/login.php")
.method(Connection.Method.GET)
.execute();
org.jsoup.nodes.Document document = Jsoup.connect("https://www.capitaliq.com/CIQDotNet/Login.aspx/authentication.php")
.data("cookieexists", "false")
.data("username", "myUsername")
.data("password", "myPassword")
.cookies(loginForm.cookies())
.post();
System.out.println(document);
} catch (IOException ex) {
Logger.getLogger(WebCrawler.class.getName()).log(Level.SEVERE, null, ex);
}
}
Besides the
username
,password
and thecookies
, the site requeires two additional values for the login -VIEWSTATE
andEVENTVALIDATION
.You can get them from the response of the first
Get
request, like this -And add it after the
password
(the order doesn't really matter) -I would also add the
userAgent
field to both requests - some sites test it and send different pages to different clients, so if you would like to get the same response as you get with your browser, add to the requests.userAgent("Mozilla/5.0")
(or whatever browser you're using).Edit
The
userName
's field name ismyLogin$myUsername
, the password ismyLogin$myPassword
and thePost
request also contains data about the login button. Ican't test it, because I don't have user at that site, but I believe it will work. Hope this solves your problem.EDIT 2
To enable the
remember me
field during login, add this line to thepost
request: