I am trying to POST data into website to make a login into the site using Jsoup , but its not working ?
I am trying the code
Document docs = Jsoup.connect("http://some.com/login") .data("cmd", "login","username", "xxxx","password", "yyyyy") .referrer("http://some.com/login/").post();
here it is giving normal page of login in pagesource
i have also tried the code
Document docs = (Document) Jsoup.connect("http://some.com/login") .data("cmd", "login","username", "xxxx","password", "yyyyy") .referrer("http://some.com/login/").method(Method.POST).execute().parse();
here also it is giving normal page of login again in pagesource.
Any suggestions regarding the same would be highly appreciated !!
Thanks....
What It Is. jsoup can parse HTML files, input streams, URLs, or even strings. It eases data extraction from HTML by offering Document Object Model (DOM) traversal methods and CSS and jQuery-like selectors. jsoup can manipulate the content: the HTML element itself, its attributes, or its text.
clean. Creates a new, clean document, from the original dirty document, containing only elements allowed by the safelist. The original document is not modified. Only elements from the dirty document's body are used.
I will give the answer of your question by taking an example. Suppose you want to login to facebook.
Then apart from username and password there are many other parameters that are also passed through POST
request. Those all parameters are hidden and are passed similarly like username and password. For Example :
If you will open the html source
of facebook , then you can see there is one parameter which is hidden is lgnrnd
and its value is 071129_5D7M
.
So there are many other parameter similar like this.You need to pass all the parameters. You should also specify the userAgent.
Document doc = Jsoup.connect("http://www.facebook.com") .data("email", "myemailid") .data("pass", "mypassword") // and other hidden fields which are being passed in post request. .userAgent("Mozilla") .post(); System.out.println(doc); // will print html source of homepage of facebook.
If the issue is a javascript redirect, you could try going into the javascript and checking if the URL it redirects to is static, and then use the redirection to gain access. I did that to access a popup box made by javascript once.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With