我試圖用Jsoup登錄到一個網站。當你手動登錄時,你的用戶名和密碼的表單有一個表單,你點擊一個按鈕將你轉到不同的頁面。Jsoup表單發佈到ASPX /相同的頁面問題
雖然它不適用於Jsoup。我懷疑問題是該頁面的URL與表單的action屬性中給出的URL相同。它也不是一個PHP頁面,而是一個ASPX頁面。任何人都可以提供幫助嗎?我的代碼如下:
private class LoginTask extends AsyncTask<String, Void, Document> {
@Override
protected Document doInBackground(String... loginInfo) {
try {
Connection.Response loginForm = Jsoup.connect("https://websiteHere.org/directory/Login_Student_PXP.aspx")
.method(Connection.Method.GET)
.execute();
currentPage = Jsoup.connect("https://websiteHere.org/directory/Login_Student_PXP.aspx")
.data("username", "usernameGoesHere")
.data("password", "passwordGoesHere")
.cookies(loginForm.cookies())
.post();
} catch(IOException e) {
System.out.println("Failed to log in.");
}
return currentPage;
}
@Override
protected void onPostExecute(Document result) {
loadPageFinished();
}
}
其他信息:我替換websiteHere.org/directory網站的名稱,但Login_Student_PXP.aspx仍然是準確的。
的形式如下:<form name="Form1" method="post" action="Login_Student_PXP.aspx" id="Form1">
它不具有在它前面的websiteHere.org/directory。
任何幫助將不勝感激!
編輯:該頁面還有兩個隱藏的輸入,<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="6A78CD7E">
和<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAATriMevoEM8VekHWnEl5C3PKhoCyVdJtLIis5AgYZ/RYe4sciJO3Hoc68xTFtZGQEgSYOQVAPr9tiF9q7nSHjzouKtiufdoMJr/iFLaXnXfphkEj5veiwEQz7j1yxouXII=">
。我嘗試將它們作爲單獨的.data命令添加到我的代碼中,但它們不會改變任何內容。