在 Apache HTTP 组件 4 类 org.apache.http.impl.auth.BasicScheme 我注意到该方法:
public static Header authenticate(
final Credentials credentials,
final String charset,
final boolean proxy)
不推荐使用以下信息:
/**
* Returns a basic <tt>Authorization</tt> header value for the given
* {@link Credentials} and charset.
*
* @param credentials The credentials to encode.
* @param charset The charset to use for encoding the credentials
*
* @return a basic authorization header
*
* @deprecated (4.3) use {@link #authenticate(Credentials, HttpRequest, HttpContext)}.
*/
@Deprecated
但是,我没有看到任何文档解释如何从废弃的函数迁移到新的函数。尽管已弃用的功能有效,但我宁愿以“正确”的方式做事。以下是我如何使用已弃用的功能:
UsernamePasswordCredentials creds = new UsernamePasswordCredentials("admin", "admin");
URI uriLogin = URI.create("http://localhost:8161/hawtio/auth/login/");
HttpPost hpLogin = new HttpPost(uriLogin);
hpLogin.setHeader(BasicScheme.authenticate(creds, "US-ASCII", false));
我怎样才能采用相同的概念并将其应用于 BasicScheme.authenticate 的“正确”方法?