我的登录过程无法正常工作

时间:2014-01-02 23:34:33

标签: java android jsoup

我正在尝试访问一些要求我先登录的页面文本。

登录页面为= https://utdirect.utexas.edu/

我到目前为止的尝试是这样的,

Response res = Jsoup
        .connect("https://utdirect.utexas.edu/") // this is the login page
        .header("LOGON", "mySchoolID")
        .header("PASSWORDS", "mySchoolIDPassword")
        .method(Method.POST)
        .execute();


    Map<String, String> loginCookies = res.cookies(); // cookies to keep me logged in



    // This is the page that required me to be loged in first
    Document doc =   Jsoup.connect("https://utdirect.utexas.edu/apps/degree/audits/requests/history/") 
            .cookies(loginCookies).get();
        Elements e = doc.getAllElements();

        for(Element e1 : e){
            Log.i("e.text()" , e.text);
        }

问题是打印出来的是登录页面而不是我想要的页面。

知道这个解决方案是什么?

1 个答案:

答案 0 :(得分:2)

发布前阅读登录表单。你缺少一些参数。检查每次登录。


    Connection.Response loginForm = Jsoup.connect("https://utdirect.utexas.edu/")
                .ignoreContentType(true)
                .userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0")
                .referrer("http://www.google.com")
                .timeout(12000)
                .followRedirects(true)
                .method(Connection.Method.GET)
                .execute();

    Connection.Response loginFormFilled = Jsoup.connect("https://utdirect.utexas.edu/")
                .ignoreContentType(true)
                .userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0")
                .followRedirects(true)
                .referrer("https://utdirect.utexas.edu/")
                .data("CDT","20140103191944")
                .data("NEW_PASSWORD", "")
                .data("CONFIRM_NEW_PASSWORD", "")
                .data("LOGON", "user")
                .data("PASSWORDS", "pass")
                .cookies(loginForm.cookies())
                .method(Connection.Method.POST)
                .execute();

     Map<String, String> cookies = loginFormFilled.cookies();