5

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();
Junaid
  • 2,572
  • 6
  • 41
  • 77
  • Why java tag here? – sForSujit Aug 04 '17 at 05:49
  • 1. Even if the field is empty/hidden it is necessary to submit it. 2. Check the post request of your browser - it contains some extra fields (with values), like __viewstate. 3. Add your user agent string to your requests. 4. There are few similar questions, like this one - https://stackoverflow.com/questions/31871801/problems-submitting-a-login-form-with-jsoup/ – TDG Aug 04 '17 at 06:13
  • @TDG Please see the updated code. – Junaid Aug 04 '17 at 07:11

1 Answers1

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:

post request

You must send all these values to the server.

Community
  • 1
  • 1
TDG
  • 5,909
  • 3
  • 30
  • 51