javaandroidjsoupformshtml-post

how to submit form without a name for the button using jsoup post request


I'm trying to POST data into a website to make a login into the site using Jsoup. This is the html form:

    <form action="/user/login" method="POST">
    <table>
    <tr>
      <td><label for="email">E-Mail:</label></td>
      <td><input name="email" value="" /></td>
    </tr>
    <tr>
      <td><label for="password">Passwort:</label></td>
      <td><input name="password" type="password" /></td>
    </tr>
    <tr>
      <td><input type="submit" value="Login" /></td>
    </tr>
    </table>
    </form>

Here is my code:

 Connection.Response loginForm = Jsoup.connect(LOGINWEBSITE)
                    .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0")
                    .method(Connection.Method.GET)
                    .execute();


            Document login = Jsoup.connect(LOGIN_URL)
                    .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0")
                    .data("cookieexists", "false")
                    .data("email", email)
                    .data("password", password)
                    .cookies(loginForm.cookies())
                    .post();

But it doesn't work. For another website I just needed to add a line for the button and it worked. Here it does not work, since the button has no name. Basically I want to know how to submit the from. How can I resolve this issue? Many thanks.


Solution

  • Often you need to access the login page with a GET request first to get all needed cookies/tokens for the post request. I can't check that for you since you did not mention the URL to which you try to connect. In your place I would record the network traffic with the browser developer tools when you manually login. Then analyze the data that actually was sent back and forth. Usually you can easily identify the necessary tokens/cookies that need to be passed along with the post request for a successful login.