Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Login Post Method to Asp.net form using Jsoup

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

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.

enter image description here

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.

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();
like image 753
Junaid Avatar asked Oct 18 '22 08:10

Junaid


1 Answers

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

post request

You must send all these values to the server.

like image 75
TDG Avatar answered Oct 21 '22 08:10

TDG