如何在 Eclipse 插件代码中使用 URLConnection 时抑制身份验证窗口

发布于 2024-11-30 23:06:43 字数 751 浏览 0 评论 0原文

我创建了一个 Eclipse 插件,并在其中通过扩展 org.eclipse.jface.wizard.Wizard 创建了一个向导。我正在使用 java.net.URLConnection 与服务器执行基本身份验证,如下所示

String auth = new String(Base64.encodeBase64((username + ":" + password).getBytes()));
log(auth);

URL url = new URL(server);
URLConnection conn = url.openConnection();

// this fails -- can't stop the auth window when the username/password are invalid
conn.setAllowUserInteraction(false);
conn.setRequestProperty("Authorization", "Basic " + auth);

monitor.beginTask("Authenticating: ", IProgressMonitor.UNKNOWN);
InputStream in = conn.getInputStream();

:密码有效,那么一切正常。但如果用户名 &如果密码不进行身份验证,Eclipse 会弹出自己的“需要密码”窗口(我不想要这个窗口——我想自己管理失败的身份验证)。我本以为 URLConnection.setAllowUserInteraction 会阻止这个,但它没有效果。

I have created an Eclipse Plugin, and within that I have created a Wizard by extending org.eclipse.jface.wizard.Wizard. In that I am using java.net.URLConnection to perform Basic Authentication with a server, like so:

String auth = new String(Base64.encodeBase64((username + ":" + password).getBytes()));
log(auth);

URL url = new URL(server);
URLConnection conn = url.openConnection();

// this fails -- can't stop the auth window when the username/password are invalid
conn.setAllowUserInteraction(false);
conn.setRequestProperty("Authorization", "Basic " + auth);

monitor.beginTask("Authenticating: ", IProgressMonitor.UNKNOWN);
InputStream in = conn.getInputStream();

If the username & password are valid, then everything works fine. But if the username & password do not authenticate, Eclipse pops up its own "Password Required" window (which I don't want -- I want to manage the failed authentication myself). I would have thought that URLConnection.setAllowUserInteraction would stop this, but it has no effect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文