如何用java实现网关

发布于 2024-10-08 03:56:35 字数 288 浏览 0 评论 0原文

我必须用java实现一个网关。 我有一个 servlet,它接收诸如要访问的 URL 和要传递到该 URL 的参数之类的信息。 我需要从那里获取响应,如果需要的话进行一些修改,然后将其传递回浏览器。

我尝试打开一个到 URL 的 HttpConnection,然后简单地在其输出流上写入,但我猜这不起作用。是否可以创建一个新的 HttpRequest 并执行它? 我怎样才能在java中实现这个?看起来 Apache httpclient 是选项之一,但我不应该使用它或任何其他外部库。

非常感谢任何帮助。

维韦克

I have to implement a Gateway in java.
I have a servlet that recieves information like the URL to hit and parameters to be passed to that URL.
I need to get the response back from there, make some modifications, if required, and pass it back to the browser.

I tried opening a HttpConnection to the URL and then simply writing on its outputstream but as i guessed thats not working. Is it possible to create a new HttpRequest and execute it?
How can i implement this in java? It looks like Apache httpclient is one of the options but i am not supposed to use that or any other external library as such.

Any help is greatly appreciated.

Vivek

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

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

发布评论

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

评论(1

蓝色星空 2024-10-15 03:56:38

尝试使用 java.net.Socket 和 java.net.ServerSocket。使用 ServerSocket,您可以侦听等待连接/请求的特定端口,使用 Socket,您可以发送请求的客户端数据并将其发送到原始服务器。这是构建您自己的网关项目的基础......

Try to use a java.net.Socket and java.net.ServerSocket. With ServerSocket, you can listen to a specific port waiting connections/requests and with Socket you can send the requested client data and sends to the original server. It's a base to build your own gateway project...

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