如何在使用 java 客户端调用 servlet 之前进行身份验证(代码)

发布于 2024-12-27 02:57:16 字数 145 浏览 2 评论 0原文

我正在尝试使用 java 调用 servlet,但在此之前我需要进行身份验证才能调用该 servlet。当我首先按照下面的示例调用 URL 时,它会被重定向到登录页面,是否有办法通过 java.lang.String 传递用户名和密码?有人可以建议如何做到这一点吗?提前致谢。

I am trying to call a servlet using java, but before that i need to get authenticated to call that servlet. when I call the URL as per the below example first it is getting redirected to login page, Is there anyway to pass the user name and password through java. Can anybody suggest how to do that? Thanks in advance.

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

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

发布评论

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

评论(1

她说她爱他 2025-01-03 02:57:16

有没有办法通过java传递用户名和密码。

对此没有一般性的答案。理论上是可以的,但实际中这取决于站点如何实现登录。

您需要查看使用网络浏览器登录该特定站点时会发生什么……并在客户端代码中重现浏览器端行为。这通常只是在 GET 请求参数或 POST 数据中发送一些参数,但它可能更复杂。

Is there anyway to pass the user name and password through java.

There is no general answer to this. Theoretically it is possible, but in practice it depends on how the site implements login.

You need to look at what happens when you login on that specific site using a web browser ... and reproduce the browser-side behavior in your client code. This is typically just a matter of sending some parameter in GET request arguments or POST data, but it could be more complicated.

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