使用 Jsoup 的簡單例份驗證 POST 請求

下面演示了一個帶有身份驗證資料的簡單 POST 請求,請注意 usernamepassword 欄位會因網站而異:

final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36";
Connection.Response loginResponse = Jsoup.connect("yourWebsite.com/loginUrl")
                                        .userAgent(USER_AGENT)
                                        .data("username", "yourUsername")
                                        .data("password", "yourPassword")
                                        .method(Method.POST)
                                        .execute();