java - 如果先初始化外观,则不调用 SOCKS 代理身份验证器
问题描述
当使用需要身份验证的系统代理并使用-Djava.net.useSystemProxies=true
选项调用 java 时,以下代码从不调用身份验证器:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
System.out.println("getPasswordAuthentication() called for " + getRequestingProtocol() + " proxy " + getRequestingHost() + ":" + getRequestingPort());
return super.getPasswordAuthentication();
}
});
new URL("https://www.google.com/").getContent();
如果外观未初始化,则调用身份验证器。这只发生在 SOCKS 代理上,始终执行 HTTP 代理的身份验证。
这是一个错误还是我做错了什么?
解决方案
推荐阅读
- python - 使用 python 套接字查看原始数据包级数据
- python-3.x - Mac OS X:从 pyzbar.pyzbar 导入解码为 opencv-python 条码阅读器失败
- bash - 如何在 docker compose 中有条件地运行命令
- python - Python csv阅读器忽略作为字符串一部分的双引号内的分隔符
- python - 访问网站时出现 Django 内部服务器错误
- c++ - 显示最大利润的步骤
- javascript - 从一个字符串中获取多个子字符串作为数组
- visual-studio - 我只是无法让搜索框出现在我的 VS studio 2010 上?
- javascript - 如果 laravel 中的条件,如何检查隐藏输入是否为空或不使用 else
- spring-boot - 将 SpringBoot / Sleuth Zipkin Traces 发送到 Honeycomb.io