事实证明,有一种简单的标准方法可以实现我想要的目标:
import java.net.Authenticator;import java.net.PasswordAuthentication;Authenticator myAuth = new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication("german", "german".toCharArray()); }};Authenticator.setDefault(myAuth);没有自定义的“ sun”类或外部依赖项,也没有手动编码任何内容。
我知道BASIC安全性不是很好,但是我们也使用HTTPS。



