如何使用java验证器检查授权是否成功?

如何使用java验证器检查授权是否成功?,java,authorization,Java,Authorization,我使用Authenticator登录到服务器,如下所示: Authenticator.setDefault (new Authenticator() { protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication ("admin", "*****".toCharArray()); } }); 它很好用。 但是如何确保授权实际上是成功的呢?

我使用Authenticator登录到服务器,如下所示:

Authenticator.setDefault (new Authenticator() {
   protected PasswordAuthentication getPasswordAuthentication() {
      return new PasswordAuthentication ("admin", "*****".toCharArray());
   }
});
它很好用。 但是如何确保授权实际上是成功的呢?

类Authenticator表示一个对象,它知道如何获得网络连接的身份验证。通常,它会通过提示用户输入信息来实现这一点。 到目前为止,您所做的是在系统中注册匿名类的一个实例,现在您所要做的就是定义一个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

这看起来像是解决办法。这是一种常见的情况。难道他们真的没有预料到不成功的授权案例吗?不幸的是,没有像
getLoginStatus()这样的东西,我认为您必须即兴创作:(