mardi 8 décembre 2015

How to login site with JSOUP?

<body onload="setFocusOnLoginForm();">
    <div class="login-container">
        <div class="login-header">
            <h2>OSS Аргус</h2>
        </div>
        <div class="login-content">
        <form method="post" action="j_security_check" name="loginform"
            id="loginform" target="_parent" style="padding: 2px;">

        <table align="center" class=loginTable>

                    <tr class="form-field">
                        <td><label for="j_username" style="white-space: nowrap;">Логин</label></td>
                        <td><input type="text" name="j_username" id="j_username" size="12"
                            value=""/>
                        </td>
                    </tr>

                    <tr class="form-field">
                        <td><label for="j_password" style="white-space: nowrap;">Пароль</label></td>
                        <td><input type="password" name="j_password" id="j_password" value="" size="12" /></td>
                    </tr>

                    <tr>
                        <td/>
                        <td><input type="submit" value="LOGIN" class="login-button" /></td>
                    </tr>

        </table>


        </form>
        </div>
    </div>



</body>

So this is the HTML body view of site, which i want to log in There is my code

protected Void doInBackground(Void... params) {

        Document doc = null;
        Document arg = null;
        try {


            disableSSLCertCheck();
            Connection.Response loginForm = Jsoup.connect("https://URL/home.seam")
                    .data("j_username", "USERNAME", "j_password", "PASSWORD", "login-button", "LOGIN")
                    .followRedirects(true)
                    .method(Connection.Method.POST)
                    .execute();
            doc = Jsoup.connect("https://URL/home.seam")
                    .userAgent("Chrome")
                    .cookies(loginForm.cookies())
                    .get();
            /*    doc = Jsoup.connect("https://URL/taskList.seam")
                    .userAgent("Mozilla")
                    .get();*/

        } catch (IOException e) {

            e.printStackTrace();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        } catch (KeyManagementException e) {
            e.printStackTrace();
        }

Whats wrong? I cant log in( I've just read Logging in to website programatically Android but in my site is not such parameters especially login-button. Please help me to fix it)

Aucun commentaire:

Enregistrer un commentaire