尝试登录网站并使用AsyncHttpConnector保存cookie

时间:2019-05-09 19:05:35

标签: java android jsoup

我使用此代码在登录页面上登录并保存cookie供以后使用。它工作了几个月,但只是停止工作,我尽了我所能,但只是不知道这是怎么回事。尝试尝试登录以下网址:list comprehension

    @Override
    public void login(final String username, final String password, final ConnectionListener listener) {
        if (username == null || password == null) {
            listener.login(Result.WRONG_CREDENTIALS);
            return;
        }
        HashMap<String, String> params = new HashMap<>();
        params.put("login-form-type", "pwd");
        params.put("password", password);
        params.put("username", username);

        new AsyncHttpConnector(LOGIN_URL, params, null, org.jsoup.Connection.Method.POST, null, false) {
            @Override
            protected void OnSucces(Document document, Map<String, String> cookies) {
                if(document.html().contains("Uw login was succesvol")){
                login_cookies.clear();
                login_cookies.putAll(cookies);
                listener.login(Result.SUCCES);
                }else{
                    if(document.html().toLowerCase().contains("wijzig het aan u toegekende wachtwoord"))
                        listener.login(Result.CREDENTIALS_EXPIRED);
                    else if(document.html().toLowerCase().contains("error during authentication"))
                        listener.login(Result.WRONG_CREDENTIALS);
                    else if(document.html().toLowerCase().contains("dit account is geblokkeerd"))
                        listener.login(Result.BLOCKED);
                    else
                        listener.login(Result.UNKOWN_ERROR);

                }
            }

            @Override
            protected void OnFail(Exception e) {
                listener.login(Result.CONNECT_ERROR);
            }
        }.execute();
    }

我希望它登录到网站并保存cookie以用于其他请求。

0 个答案:

没有答案
相关问题