1

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.

PoomaniGP
  • 80
  • 1
  • 1
  • 11
  • 1
    Q: Why do you send "btnlogin" as a parameter at the `get` request? A: Because you've checked the `post` request with the browser's dev tools and sawe it. Q: Then why don't you send all the other parameters, like __EVENTTARGET, __EVENTVALIDATION and so on? – TDG Sep 14 '17 at 15:57
  • But what are the values that has to passed along with __EVENTTARGET ,and __EVENTVALIDATION, thats where I'm stuck at. – PoomaniGP Sep 14 '17 at 18:18
  • 1
    You can find them in the response for the first `get` request. – TDG Sep 15 '17 at 05:24
  • I'm not well versed with jsoup. So, can you help with the code to find'em? – PoomaniGP Sep 15 '17 at 06:50
  • Look here, it is very similar - https://stackoverflow.com/questions/31871801/problems-submitting-a-login-form-with-jsoup/31877829#31877829 – TDG Sep 15 '17 at 06:59
  • Thank you. I'll give it a try and I'll let you know asap. – PoomaniGP Sep 15 '17 at 07:15
  • Thanks a lot. Finally it worked. I passed along with __VIEWSTATE and __EVENTVALIDATION and it worked like charm. Thanks again. I've been cracking my head for a long time to get this done. – PoomaniGP Sep 16 '17 at 04:56

0 Answers0