学校のウェブサイト(reggienet.illinoisstate.edu)用のアプリケーションを作成しようとしていますが、ログインを入力して自分のCookieに保存することに問題があります私はウェブを精査して見つけたものすべてを試しましたが、何も動いていません。私は完全に失われています。ここでhtmlUnitを使用して学校のウェブサイトにログインする
は、私が今持っているコード
public void login()
{
HtmlPage currentPage = null;
Scanner keyboard = new Scanner(System.in);
WebClient webClient = new WebClient();
try
{
webClient = reggieLogin(webClient, keyboard);
}
catch (Exception e)
{
e.printStackTrace();
}
try
{
currentPage = webClient.getPage(""https://reggienet.illinoisstate.edu/portal"");
}
catch (FailingHttpStatusCodeException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (MalformedURLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
String pageSource = currentPage.asXml();
System.out.print(pageSource);
}
private WebClient reggieLogin(WebClient webClient, Scanner keyboard) throws Exception
{
webClient.getOptions().setJavaScriptEnabled(false);
HtmlPage currentPage = webClient.getPage("https://account.illinoisstate.edu/centrallogin/"); //Load page at the STRING address.
HtmlInput username = currentPage.getElementByName("username"); //Find element called loginuser for username
System.out.print("ULID: ");
username.setValueAttribute(keyboard.nextLine()); //Set value for username
HtmlInput password = currentPage.getElementByName("password"); //Find element called loginpassword for password
System.out.print("Password: ");
password.setValueAttribute(keyboard.nextLine()); //Set value for password
HtmlButtonInput submitBtn = currentPage.getElementByName("submit"); //Find element called Submit to submit form.
currentPage = submitBtn.click(); //Click on the button.
return webClient;
}
誰もが任意のヘルプを提供することができますがある、または誰もがこのコードで間違っているものを見ることができますか?
おそらくJavaScriptEnabledをtrueに設定する必要がありますか?現代のほとんどのウェブサイトでJavaScriptが有効になっている必要があるため、不思議に思っています。 –
さて、私はそれを試みたが、残念ながらそれは動作しませんでした、それはまだ私がログインしていることを認識しません – Andrew