How to post form login using jsoup?

The URL that are you using in order to do the POST request is wrong, simply because when you have to do a specific request to a form you should use the web page that is present in the form tag, in this case “authentication.php”.

So the code will be:

    package jsouptest;

    import org.jsoup.Connection;
    import org.jsoup.Jsoup;
    import org.jsoup.nodes.Document;

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

           Connection.Response loginForm = Jsoup.connect("https://www.desco.org.bd/ebill/login.php")
            .method(Connection.Method.GET)
            .execute();

           Document document = Jsoup.connect("https://www.desco.org.bd/ebill/authentication.php")
            .data("cookieexists", "false")
            .data("username", "32007702")
            .data("login", "Login")
            .cookies(loginForm.cookies())
            .post();
           System.out.println(document);

       }

    }

This one correctly retrieves the web page that you want.

Leave a Comment