使用Jsoup登录Asp.net表单的方法

时间:2022-10-31 09:33:32

I am trying to login to http://www.investabroadproperties.com/ site using following code

我正在尝试使用以下代码登录http://www.investabroadproperties.com/ site

Connection.Response loginForm = Jsoup.connect("http://www.investabroadproperties.com/")
                .method(Connection.Method.GET)
                .execute();

        Document document = Jsoup.connect("http://www.investabroadproperties.com/")
                .data("ctl00$ctl02$tbEmail", "myemail")
                .data("ctl00$ctl02$tbPassword", "mypassword")
                .cookies(loginForm.cookies())
                .post();

But I am unable to login to this site. By looking into the html source of the site, I see that there are some hidden fields as shown below but with empty values. Also there is an attribute onsubmit="javascript:return WebForm_OnSubmit();", I am not sure how to use it.

但我无法登录此网站。通过查看网站的html源代码,我看到有一些隐藏字段,如下所示,但值为空。还有一个属性onsubmit =“javascript:return WebForm_OnSubmit();”,我不知道如何使用它。

使用Jsoup登录Asp.net表单的方法

I also see this post, but I couldn't understand the logic/code that is given in the accepted answer (may be that one will help).

我也看到了这篇文章,但我无法理解接受的答案中给出的逻辑/代码(可能会有所帮助)。

Can anybody help me out that how can I login to the site?

任何人都可以帮助我,我该如何登录该网站?

I am using java and jsoup.

我正在使用java和jsoup。

EDIT

I also tried below code but still no luck

我也试过下面的代码,但仍然没有运气

Connection.Response loginForm = Jsoup.connect("http://www.investabroadproperties.com/")
                .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1")
                .method(Connection.Method.GET)
                .execute();

        Document doc = loginForm.parse();

        Elements hiddenElems = doc.select("input[type=hidden]");
        Map<String, String> nameValue = new HashMap<>();

        for(Element elem : hiddenElems) {
            nameValue.put(elem.attr("name"), elem.attr("value"));
        }

        Document document = Jsoup.connect("http://www.investabroadproperties.com/")
                .userAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.112 Safari/535.1")
                .data("ctl00$ctl02$tbEmail", "myValidEmail")
                .data("ctl00$ctl02$tbPassword", "myValidPassword")
                .data(nameValue)
                .cookies(loginForm.cookies())
                .post();

1 个解决方案

#1


3  

The following image was taken from my browser's developer tools. As you can see, you are still missing some values in your request:

以下图片来自我的浏览器的开发人员工具。如您所见,您仍然遗漏了请求中的某些值:

使用Jsoup登录Asp.net表单的方法

You must send all these values to the server.

您必须将所有这些值发送到服务器。

#1


3  

The following image was taken from my browser's developer tools. As you can see, you are still missing some values in your request:

以下图片来自我的浏览器的开发人员工具。如您所见,您仍然遗漏了请求中的某些值:

使用Jsoup登录Asp.net表单的方法

You must send all these values to the server.

您必须将所有这些值发送到服务器。