首页javajsoupJava HTML/XML - 如何使用jsoup的post表单登录

Java HTML/XML - 如何使用jsoup的post表单登录

我们想知道如何使用jsoup的post表单登录。
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

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

    Connection.Response loginForm = Jsoup
        .connect("https://www.your server.com/login.php")
        .method(Connection.Method.GET).execute();

    Document document = Jsoup
        .connect("https://www.your server.com/authentication.php")
        .data("cookieexists", "false").data("username", "YourName")
        .data("login", "Login").cookies(loginForm.cookies()).post();
    System.out.println(document);

  }

}