分析我的 Java 代码发送的 http 流量的最佳方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4853094/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 08:20:04  来源:igfitidea点击:

Best way to analyze http traffic sent by my java code?

javahttptrafficsniffer

提问by Chris Knight

I have some java code both new (using Apache commons http libraries) and old (strictly using java 1.4 API) and am trying to rewrite the old code using the newer apache commons libraries. However, it isn't working and I'm struggling to find out why. The requests are being sent, but my newer code times out on the receiving server which I don't have access to. Since the old code works, I must have mucked up the http request. It would be very useful to use some sort of HTTP traffic sniffer to examine exactly what is being sent so I can see what differences there are.

我有一些新的(使用 Apache 公共 http 库)和旧的(严格使用 java 1.4 API)的 java 代码,我正在尝试使用较新的 apache 公共库重写旧代码。但是,它不起作用,我正在努力找出原因。正在发送请求,但我的新代码在我无权访问的接收服务器上超时。由于旧代码有效,我一定是搞砸了 http 请求。使用某种 HTTP 流量嗅探器来准确检查发送的内容非常有用,这样我就可以看到存在哪些差异。

I've downloaded a few http sniffers from the web (this oneand that one) but neither capture any of the http data being sent by my java code (but they do work when I send random requests from a browser). Any ideas out there on how I can get my hands on this data?

我已经从网上下载了一些 http 嗅探器(这个那个),但都没有捕获我的 java 代码发送的任何 http 数据(但是当我从浏览器发送随机请求时,它们确实可以工作)。关于如何获得这些数据的任何想法?

回答by Sdaz MacSkibbons

Use wireshark.

使用wireshark

It's great, free, open-source, cross-platform, and can highlight different network layers, and it's not running from some dubious website that looks like SEO spam.

它很棒、免费、开源、跨平台,并且可以突出显示不同的网络层,而且它不是从一些看起来像 SEO 垃圾邮件的可疑网站上运行的。

Snortis another good one, but it's more geared toward intrusion detection and automated responses to that. Still, it has a great sniffer.

Snort是另一个不错的选择,但它更适合入侵检测和对此的自动响应。不过,它有一个很棒的嗅探器。

回答by Uriah Carpenter

Typically I find that packet sniffing is too low level for troubleshooting HTTP. Try a reverse proxy; personally I like Charlesas it works the same in Windows, Mac OS X and Linux; Fiddleris a popular on Windows.

通常,我发现数据包嗅探对于 HTTP 故障排除来说太低了。尝试反向代理;我个人喜欢Charles,因为它在 Windows、Mac OS X 和 Linux 中的工作方式相同;Fiddler在 Windows 上很流行。

回答by bestsss

you can specify SOCKS Proxy. normally Java uses SocksSocketImpl - i.e. it supports automatically SOCKS proxies.

您可以指定 SOCKS 代理。通常 Java 使用 SocksSocketImpl - 即它自动支持 SOCKS 代理。

Any other sniffer will do as well

任何其他嗅探器也可以

回答by Ratinho

If you try to sniff your loopback(127.0.0.1) - thats bit complicated and you should install special driver for that.
I'd suggest you to send request to "fake" server and than sniff it.
u can sniff with "WireShark" or "burpSuite" (if u can configure ur program that go through proxy server).
gl.

如果您尝试嗅探您的环回 (127.0.0.1) - 那有点复杂,您应该为此安装特殊的驱动程序。
我建议您将请求发送到“假”服务器而不是嗅探它。
您可以使用“WireShark”或“burpSuite”进行嗅探(如果您可以配置通过代理服务器的程序)。
gl.