0

So I'm trying to log in to a webpage using Jaunt. The first thing to mention is that the webpage is .aspx and the submit button has an option onclick="javascript:WebForm_DoP..." and as far as I know Jaunt doesn't support Javascript right? In case I'm wrong, the code I'm using is the one in the examples of Jaunt:

Form form = userAgent.doc.getForm(0);
form.setTextField("Login1$UserName","USER");
form.setPassword("Login1$Password","PASSWORD");
form.setCheckBox("Login1$RememberMe",false);
form.submit("GO");
System.out.println(userAgent.getLocation());

All the names and values are correct, and the user and password works since I can log in using the web browser. After I execute the code, in the output I get this:

message: UserAgent.sendPOST; Connection error requestUrl: http://webpagehere.com/default.aspx [posting __VIEWSTATE=%2FwEPDwUJLTk5MDc0NjQ2ZBgBBR5fX0NvbnRyb2xzUmVxdWlyZVBvc3RCYWNrS2V5X18WAgURTG9naW4xJFJlbWVtYmVyTWUFF0xvZ2luMSRMb2dpbkltYWdlQnV0dG9upWcarODJIwpeMt8HCmfaBn6iMWI%3D&__VIEWSTATEGENERATOR=CA0B0334&Login1%24UserName=USER&Login1%24Password=PASSWORD&Login1%24LoginButton=GO] response: [none]

The form div is this one:

<form name="form1" method="post" action="Default.aspx" onsubmit="javascript:return WebForm_OnSubmit();" id="form1" style="text-align:center">

Any ideas what could be my problem? In case Jaunt doesn't allow me to do this login, could someone please recommend me a library for web scraping and interaction? Thanks!

lpares12
  • 3,504
  • 4
  • 24
  • 45

1 Answers1

0

Seems like you are stuck. Actually .aspx pages uses AJAX pagination. You will have to extract the values of __VIEWSTATE, __VIEWSTATEGENERATOR and all other form values and then send them with POST method in the request body. You can use Fiddler to get the request body which contains all these hidden variables and your entries to the form.

In Java you can use Selenium Or HTMLUnit which are Java GUI-Less browser, supporting JavaScript, to run agains web pages.

edit: You can use Jaunt-api as well, I just tried it with it, all you do is send a POST request alongwith the request-body, you can easily check it with Fiddler, and it works!!

Form values in HTTP POSTs are sent in the request body, in the same format as the querystring. You can find the request body of a link by inspecting it using the Fiddler and then copy request body from Textview and send the encoded data as request body.

UserAgent userAgent = new UserAgent();
userAgent.sendPOST("<your link to form page>","<request body>");
amor.fati95
  • 119
  • 1
  • 11
  • Can you make it more clear? What do yo mean by headers? Can you write the code to explain? – kerberos84 Jul 10 '15 at 09:03
  • if still its not clear, send me a .aspx link and i will provide you the approach – amor.fati95 Jul 10 '15 at 11:00
  • Let's say facebook login page. – kerberos84 Jul 10 '15 at 20:54
  • it uses a https, a secure channel, you cant just get the request message for it.. provide me a simple link that uses http connection. – amor.fati95 Jul 11 '15 at 05:27
  • You mean jaunt does not support it? Because i can log in (not on facebook another https login page) using standard java libraries. java.net.URL url = new URL(null, LOGIN_POST_PAGE, new sun.net.www.protocol.https.Handler()); – kerberos84 Jul 11 '15 at 14:22
  • jaunt supports it, its a GUI-Less browser so it will have all functionalities like a browser but you will have to do the extra work of indentifying the request body of the POST method and then modify it according to your use. – amor.fati95 Jul 13 '15 at 04:26