Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;
import org.jsoup.Connection;
import org.jsoup.Connection.Method;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;

public class Main {
    public static String POST_URL = "https://www.%s/login";

    public static Document getPage(String strProvider, String strUsername, String strPassword) throws IOException {

        Connection.Response resResponse = Jsoup.connect(String.format(POST_URL, strProvider)).execute();

        Element eleHidden = resResponse.parse().select("input[type=hidden]").first();

        Document docBody = Jsoup.connect(String.format(POST_URL, strProvider))
                .data(eleHidden.attr("name"), eleHidden.attr("value"), "login[username]", strUsername,
                        "page_referrer", "login", "login[password]", strPassword)
                .method(Method.POST).followRedirects(true).cookie("PHPSESSID", resResponse.cookie("PHPSESSID"))
                .execute().parse();

        return docBody;

    }
}