private String getRealm ( String sUrl ) throws IOException , ModuleException { AuthorizationHandler ah = AuthorizationInfo . getAuthHandler ( ) ; try { URL url = new URL ( sUrl ) ; HTTPConnection connection = new HTTPConnection ( url ) ; connection . removeModule ( CookieModule . class ) ; AuthorizationInfo . setAuthHandler ( null ) ; HTTPResponse resp = connection . Get ( url . getFile ( ) ) ; String authHeader = resp . getHeader ( "WWW-Authenticate" ) ; if ( authHeader == null ) { return null ; } String realm = authHeader . split ( "=" ) [ 1 ] ; realm = realm . substring ( 1 , realm . length ( ) - 1 ) ; return realm ; } finally { AuthorizationInfo . setAuthHandler ( ah ) ; } }
Get realm by URL .