java - 我的登录程序运行不正常

标签 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);
        }

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

知道这个问题的解决方案是什么吗?

最佳答案

发帖前阅读登录表单。您缺少几个参数。每次登录都要检查它们。


    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();

关于java - 我的登录程序运行不正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20893950/

相关文章:

android - 如何在Android中单击Alert Box中的按钮时关闭应用程序?

java - 将 &nbsp 作为字符串处理

java - Jsoup 选择命令

java - (SQL + Hibernate) 统计 12 个月前的记录

java - Apache CXF 中的 Web 服务错误

java - 涟漪效应源代码究竟是如何工作的?

java - ANDROID-JAVA - HTML 解析 - 隐藏输入

java - LibGDX - 在我的案例的 AssetManager 中计算了多少引用?

java - 代理设计模式的使用

android - Facebook Messenger 可访问性