【问题标题】:Authorization in osticket using Java in Android在 Android 中使用 Java 在 osticket 中进行授权
【发布时间】:2018-04-23 02:32:39
【问题描述】:

嗯,主要思想是获取 cookie,然后从 https://support.tltsu.ru/ 解析信息。 好吧,我们在https://support.tltsu.ru/login.php页面上看到了表单,我们需要使用POST输入“登录名”和“密码”。

<form action="login.php" method="post" id="clientLogin" onsubmit="return C1heckFields()">
<!--?php csrf_token(); ?-->
<strong></strong>
<br>

<div>
    <label for="email">Логин:</label>
<input id="myl" type="text" name="login" size="16" value="">
</div>

<div>
    <label for="ticketno">Пароль:</label>
    <input id="ticketno" type="password" name="password" size="16" value="">
</div>
<p>
    <input class="btn" type="submit" value="Войти">
</p>  
</form>

而且我还看到我们需要在 cookie 中输入 PHPSESSID。 好的。所以计划是首先启动cookies,然后在我们的POST请求中输入它们。不知道如何,但之后我们的 cookie(PHPSESSID 未更改)变得有效,甚至连接到我们的帐户。 所以,你可以说,你还有什么?然后我可以告诉你——授权在 android 中对我不起作用。 我正在使用 Jsoup - html 框架,这里是我的代码:

    class ApplicationsAuth extends AsyncTask<Void, Void, Void> {
    protected Map<String, String> applicationsAuthCookies = null;
    protected String userLogin;
    protected String userPassword;
    protected String userName;

    public ApplicationsAuth(String login, String password)
    {
        this.userLogin = login;
        this.userPassword = password;
    }

    @Override
    protected Void doInBackground(Void... params) {

        Document testPage = null;

        Connection.Response authStartResponse = null;
        Connection.Response authFinalResponse = null;


        try {
            authStartResponse = Jsoup.connect("http://support.tltsu.ru/")
                    .method(Connection.Method.GET)
                    .timeout(3500)
                    .execute();

            try {
                authFinalResponse = Jsoup.connect("http://support.tltsu.ru/login.php")
                        .timeout(3500)
                        .data("login", userLogin)
                        .data("password", userPassword)
                        .method(Connection.Method.POST)
                        .cookies(authStartResponse.cookies())
                        .execute();
                applicationsAuthCookies = authStartResponse.cookies();
                testPage = authFinalResponse.parse();
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                if (applicationsAuthCookies != null) {
                    testPage = Jsoup.connect("http://support.tltsu.ru/")
                            .cookies(applicationsAuthCookies)
                            .timeout(3000)
                            .get();
                    userName = testPage.select("div#container > div#header > p").text();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
            super.onPostExecute(result);

    }
}

授权永远不会发生。有什么建议? (用户名用于接受或不接受成功验证的事实,但即使您尝试查看 testPage 中的内容也没什么好用的 - 只是使用主页,没有任何验证提示)

【问题讨论】:

    标签: java android html post cookies


    【解决方案1】:

    终于! 不知道它是如何工作的,但现在一切正常。

       class ApplicationsAuth extends AsyncTask<Void, Void, Void> {
        protected Map<String, String> applicationsAuthCookies = null;
        protected String userLogin;
        protected String userPassword;
        protected String userName;
    
        public ApplicationsAuth(String login, String password)
        {
            this.userLogin = login;
            this.userPassword = password;
        }
    
        @Override
        protected Void doInBackground(Void... params) {
    
            Document testPage = null;
    
            Connection.Response authStartResponse = null;
            Connection.Response authFinalResponse = null;
    
    
            try {
                authStartResponse = Jsoup.connect("https://support.tltsu.ru/")
                        .method(Connection.Method.GET)
                        .timeout(3500)
                        .execute();
    
                try {
                    authFinalResponse = Jsoup.connect("https://support.tltsu.ru/login.php")
                            .userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36")
    
                            .data("login", userLogin)
                            .data("password", userPassword)
                            .cookies(authStartResponse.cookies())
                            .method(Connection.Method.POST)
                            .timeout(3500)
                            .execute();
                    applicationsAuthCookies = authStartResponse.cookies();
                    testPage = authFinalResponse.parse();
                } catch (IOException e) {
                    e.printStackTrace();
                }
    
                try {
                    if (applicationsAuthCookies != null) {
                        testPage = Jsoup.connect("https://support.tltsu.ru/")
                                .cookies(applicationsAuthCookies)
                                .timeout(3000)
                                .get();
                        userName = testPage.select("div#container > div#header > p").text();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
    
            return null;
        }
    
        @Override
        protected void onPostExecute(Void result) {
                super.onPostExecute(result);
    
        }
    }
    

    如果有人需要,这里的代码现在对我来说是可行的。

    【讨论】:

      猜你喜欢
      • 2014-10-05
      • 1970-01-01
      • 2021-11-16
      • 1970-01-01
      • 2021-06-09
      • 2020-12-17
      • 1970-01-01
      • 2021-10-12
      • 1970-01-01
      相关资源
      最近更新 更多