有没有办法从 Java servlet 处理程序获取原始 http 请求流?

编程入门 行业动态 更新时间:2024-10-28 03:18:53
本文介绍了有没有办法从 Java servlet 处理程序获取原始 http 请求流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试进行一些日志记录以捕获进入我的应用程序的原始 http 请求.我的 Java 代码位于 SpringMVC 控制器中.我可以访问HttpServletRequest"对象.但是我找不到从中获取原始 http 请求流的方法.有一个阅读器,但只阅读帖子内容.我想要的是整个shebang,网址,标题,正文.是否有捷径可寻?

I am trying to put some logging to capture the raw http request coming to my application. My Java code is inside a SpringMVC controller. I have access to the "HttpServletRequest" object. But I could not find a way to get the raw http request stream out of it. There is a reader but only reads the post content. What I want is the whole shebang, the url, the headers, the body. Is there an easy way to do this?

提前致谢.

推荐答案

不,servlet 不提供 api 来获取原始请求 - 为此,您可能需要像 wireshark 这样的嗅探器.

No, servlets provide no api to get at the raw request - you might need a sniffer like wireshark for that.

您可以获取解析的请求标头和 uri:

You can get at the parsed request headers and uri though:

  • getHeaderNames()
  • getRequestURI()

更多推荐

有没有办法从 Java servlet 处理程序获取原始 http 请求流?

本文发布于:2023-11-25 13:37:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1629968.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:没有办法   原始   程序   servlet   Java

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!