I am trying to login to this website.
Here is what I have tried so far, but it doesn't seem to work:
try{
Connection.Response login = Jsoup.connect("login_url").method(Connection.Method.GET).execute(
Connection.Response doc = Jsoup.connect("https://ecampus.psgtech.ac.in/studzone/")
.data("Txtstudid","id")
.data("TxtPasswd","password")
.data("btnlogin","Login")
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0")
.method(Connection.Method.POST).execute(); //doesn't seem to work.
Document docs=Jsoup.connect("https://ecampus.psgtech.ac.in/studzone/AttWfPercView.aspx/") //after login
.cookies(doc.cookies())
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0").get();
test=docs.title();
}catch (IOException e){
test=e.getMessage();
}
out.setText(docs.title());
What am I doing wrong?
Edit 1 Finally with help of TDG i found the flaw.
For users seeking solution for this, the actual issue is you are not passing enough data to login.
STEP 1: Go to Chrome load the page then, Options>Tools>Developer Tools
STEP 2: In the console type $("input") This will return all the inputs required in the form STEP 3: Append the data to your Response like this.
Jsoup.connect("login_url")
.data("username","user")
.data("password","password")
.data("btnlogin","Login")
.data("id_of_the_data_required","value")
.data("...and so on like this...)
.userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:50.0) Gecko/20100101 Firefox/50.0")
.method(Connection.Method.POST).execute();
STEP 4: Crawl the webpage's html code and find whether you have to use POST or GET method and its recommend to use userAgent.
STEP 5: Once you find the login event successful. Use the Response_name. cookies() to go the other urls in the page.
Hope this helps.