1

I would like to inspect the response generated by the following html code .

<form class="init" action="Initz.php" method="post">
<table border="0" cellpadding="6" cellspacing="0">
<tr><td>Name</td><td><input type="text" name="name" class="init"></td></tr>
<tr><td>Password</td><td><input type="text" name="pass" class="init"></td></tr>
<tr><td colspan=2><input type="radio" name="x" value="1" checked="checked">Enter</td></tr>
<tr><td colspan=2><input type="radio" name="x" value="2">Register</td></tr>
<tr><td colspan=2><input type="submit" value="Login"> &nbsp <input type="reset" value="Reset"></td></tr>
</table>
</form>

The page contains 2 input text fields , handled by the attributes "text" , 2 radio inputs , with the "Enter" one being selected by default and 2 buttons , which have no "name"-attribute and therefore i have no idea how to handle them.

So far , i have tried several alternatives with Jsoup and basically focused on the following code ,but instead of getting the response , i keep getting the starting page's code , probably due to the incomplete request being sent:

Document doc = Jsoup.connect("example http")
                     .data("name","myname")
                     .data("pass","mypass")
                     .data("x","1")
                     .post();

How could i effectively handle the last input line and post the request ?

Argusr8
  • 11
  • 2
  • 2
    You have to check the request as the browser sends it - probably it has more information, like cookies etc. If you add the URL to the question, it wil be easier to understand. – TDG Jul 19 '15 at 15:32
  • @TDG Using FormElement may be faster. See : http://stackoverflow.com/questions/31190892/how-to-fill-a-form-with-jsoup?lq=1 – Stephan Feb 16 '16 at 10:44
  • @Stephan Cool! I didn't know that. Looks very useful, thanks. – TDG Feb 16 '16 at 16:40

1 Answers1

1

You can ask Jsoup to send the form for you. Just pass it the variables values for (name, pass and x) ant it will do the rest.

See here for details: How to fill a form with Jsoup?

Community
  • 1
  • 1
Stephan
  • 41,764
  • 65
  • 238
  • 329