是否可以获取HttpExchange的原始请求?
如何从 com.sun.net.httpserver.HttpExchange 获取原始请求?
我正在使用 HttpServer
来制作代理,因此我想获取原始 http 请求并将其发送到原始主机。
How can I get the raw request from com.sun.net.httpserver.HttpExchange
?
I'm using HttpServer
to make a proxy, so I want to get the raw http request and send it to the original host.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
HttpExchange
API 不支持此功能。您(当然)可以自由地创建自己的类来扩展 HttpExchange 并根据需要实现其方法。 (该类实际上只是一组抽象方法。)唯一的其他可能性是查看 Sun/Oracle 代码库中
HttpExchange
的某些现有实现。我对如何有效实现
HttpExchange
的直觉是,通用实现不会捕获原始请求消息。即使确实如此,您也必须“探索”代码不应直接使用的类的内部结构。出于显而易见的原因,这是一个坏主意。
The
HttpExchange
API does not support this. You are (of course) free to create your own class that extendsHttpExchange
and implements its methods however you want. (The class is really just a set of abstract methods.)The only other possibility would be to look at some existing implementation of
HttpExchange
in the Sun/Oracle codebase.My intuition of how
HttpExchange
would be implemented efficiently is that a generic implementation wouldn't capture the raw request message.Even if it did, you would have to "poke around" with the internals of a class that your code shouldn't be using directly. This is a bad idea for obvious reasons.