如何使用 java Authenticator 检查授权是否成功?

How can I check if authorization is successful using java Authenticator?

我是这样用Authenticator登录服务器的:

Authenticator.setDefault (new Authenticator() {
   protected PasswordAuthentication getPasswordAuthentication() {
      return new PasswordAuthentication ("admin", "*****".toCharArray());
   }
});

它工作正常。 但是怎么才能保证真的授权成功呢?

class Authenticator 表示知道如何获取网络连接身份验证的对象。通常,它会提示用户输入信息。

到目前为止你所做的就是在系统中注册一个匿名class的实例,现在你所要做的就是定义一个URL并连接到它。

URL url = new URL("http://192.168.1.1/");// Connecting to this URL requires username and password to be entered.

但是我认为没有一种通用的方法来检查登录是否成功,例如,我认为您将不得不阅读对 http 响应的解析并尝试从中提取有用的信息。

if (response.contains("HREF=css/login.css"))
//login failed