使用Jsoup到登录后的数据数据、Jsoup

2023-09-05 02:40:27 作者:眉眼如初

我试图登录到这个网站: http://deeproute.com

I'm trying to log into this website: http://deeproute.com

这是我的code。

            Connection.Response res = null;
            Connection homeConnection = null;
            Document homePage = null;
            Map<String, String> loginCookies = null;
            try {
                res = Jsoup.connect("http://www.deeproute.com/")
                        .data("cookieexists", "false")
                        .data("name", user)
                        .data("password", pswd).method(Method.POST)
                        .execute();

            } catch (IOException e) {

                e.printStackTrace();
            }

            if (res != null) {

                loginCookies = res.cookies();

                try {
                    homePage = Jsoup.connect("http://www.deeproute.com")
                            .cookies(loginCookies).get();
                } catch (IOException e) {
                    e.printStackTrace();
                }

不幸的是,这只是简单地返回同一页面中一个不登录的状态。我究竟做错了什么?

Unfortunately, this simply returns the same page in a not-logged-in state. What am I doing wrong?

推荐答案

您需要发布之前阅读的形式!你缺少参数subbera =登录。

You need to read form before posting! You are missing param subbera=Login.

public static void main(String[] args) throws Exception {

    Connection.Response loginForm = Jsoup.connect("http://deeproute.com/deeproute/default.asp")
            .method(Connection.Method.GET)
            .execute();

    Document document = Jsoup.connect("http://deeproute.com/deeproute/default.asp")
            .data("cookieexists", "false")
            .data("name", "username")
            .data("password", "pass")
            .data("subbera", "Login")
            .cookies(loginForm.cookies())
            .post();

}