Reputation: 665
After trying out different tutorials and reading lots of posts here I still can't manage to login to a website using jsoup.
This is my code
Connection.Response response = Jsoup.connect("https://www.ivolatility.com/login.j")
.method(Connection.Method.GET)
.execute();
response = Jsoup.connect("https://www.ivolatility.com/login.j")
.data("username", username)
.data("password", password)
.cookies(response.cookies())
.method(Connection.Method.POST)
.execute();
Document homePage = Jsoup.connect("http://www.ivolatility.com/options.j")
.cookies(response.cookies())
.get();
Upvotes: 0
Views: 184
Reputation: 6151
Check the post
request that the browser sends (use your browser's developer tools) - it sends some extra parameters that you don't send. Add them to your reauest:
response = Jsoup.connect("https://www.ivolatility.com/login.j")
.data("username", username)
.data("ref_url", "")
.data("service_name", "")
.data("step", "1")
.data("login__is__sent", "1")
.data("password", password)
.cookies(response.cookies())
.method(Connection.Method.POST)
.execute();
It will also be wise to add the user agent
string of your browser to the request, since your program may send its own string, resulting in a total different response from the browser.
Upvotes: 2