如何用java实现网关
我必须用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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用 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...