简体   繁体   English

当我登录网站时,jsoup不会返回所有cookie

[英]jsoup does not return all cookies when I login to a website

I'm trying to login to a website, but my code returns only 2 cookies instead of more than 10 cookies. 我正在尝试登录网站,但是我的代码仅返回2个cookie,而不是10个以上的cookie。 Here is what I'm using: 这是我正在使用的:

cookies = Jsoup.connect("https://www.e-cigarette-forum.com/forum/login")
                .userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36")
                .data("login", "username")
                .data("register", "0")
                .data("password", "password")
                .data("submit", "Log in")
                .data("remember", "1")
                .data("cookie_check", "1")
                .data("_xfToken", "")
                .data("redirect", "https://www.e-cigarette-forum.com/forum/")
                .followRedirects(false)
                .method(org.jsoup.Connection.Method.POST).timeout(50000).execute().cookies();

When I print the cookies I got the following cookies: 当我打印cookie时,我得到以下cookie:

xf_session = c683e3cd72e296ec0bc8d4e36403fc1a xf_session = c683e3cd72e296ec0bc8d4e36403fc1a

__cfduid = d82ccf7651e7a7cf07c102a7782476c081436435336 __cfduid = d82ccf7651e7a7cf07c102a7782476c081436435336

Does anyone know what am I missing? 有人知道我在想什么吗?

Instead: 代替:

https://www.e-cigarette-forum.com/forum/login https://www.e-cigarette-forum.com/forum/login

You must use: 您必须使用:

https://www.e-cigarette-forum.com/forum/login/login https://www.e-cigarette-forum.com/forum/login/login

在此处输入图片说明

Working code: 工作代码:

try {

            String url = "https://www.e-cigarette-forum.com/forum/login/login/";

            Connection.Response response = Jsoup.connect(url)
                    .userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36")
                    .data("login", "username")
                    .data("password", "password")
                    .method(Connection.Method.POST)
                    .followRedirects(true)
                    .execute();

            Document document = response.parse();

            System.out.println("Hi " + document.select(".username.NoOverlay").html());

            Document doc = Jsoup.connect("https://www.e-cigarette-forum.com/forum/account/personal-details")
                    .userAgent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152 Safari/537.36")
                    .cookies(response.cookies())
                    .followRedirects(true)
                    .get();

            System.out.println(doc);

        } catch (IOException e) {
            e.printStackTrace();
        }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM