使用jpcap捕获html

发布于 2024-09-17 11:46:26 字数 712 浏览 3 评论 0原文

当我发出 HTTP 请求时,我试图打印出响应数据,其中 jpcap 正在嗅探数据包。

我已经设法获取一些标头信息,但无法获取实际的 HTML 内容。这是我正在使用的代码:

    try {
        NetworkInterface[] devices = JpcapCaptor.getDeviceList();

        System.out.println("Opening interface");
        JpcapCaptor captor=JpcapCaptor.openDevice(devices[0], 65535, true, 20);
        captor.setFilter("ip and tcp", true);

        while(true) {
            Packet thisPacket = captor.getPacket();

            if(thisPacket != null) {
                TCPPacket p = (TCPPacket)thisPacket;
                System.out.println(p.toString());
            }
        }

    } catch (Exception e) {
        System.out.println("Error: " + e );
    }

感谢您的帮助

I'm trying to print out the response data when I make a HTTP request, where jpcap is sniffing the packets.

I've managed to get some header info, but I can't get the actual HTML contents. This is the code I'm using:

    try {
        NetworkInterface[] devices = JpcapCaptor.getDeviceList();

        System.out.println("Opening interface");
        JpcapCaptor captor=JpcapCaptor.openDevice(devices[0], 65535, true, 20);
        captor.setFilter("ip and tcp", true);

        while(true) {
            Packet thisPacket = captor.getPacket();

            if(thisPacket != null) {
                TCPPacket p = (TCPPacket)thisPacket;
                System.out.println(p.toString());
            }
        }

    } catch (Exception e) {
        System.out.println("Error: " + e );
    }

Thanks for the help

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

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

发布评论

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

评论(1

眸中客 2024-09-24 11:46:26

由于您可以读取 HTTP 标头,但无法读取 HTML 内容,因此我猜测 HTTP 响应的正文已被压缩(例如,使用 gzip)。您可以识别压缩响应,因为 HTTP 响应标头包含如下行:

Content-Encoding: gzip

如果您可以发布程序的示例输出,我们可以证实这一理论。在这种情况下,您应该使用解压缩实体主体来获取服务器发送的HTML。

有关 HTTP 内容编码的更多信息,请参阅 RFC 2616

Since you are able to read the HTTP header but you can't read the HTML content, my guess is that the body of the HTTP response has been compressed (for example, using gzip). You can recognize compressed responses because the HTTP response header contains a line like:

Content-Encoding: gzip

If you could post an example output of your program, we could confirm this theory. In such case, you should use the decompress the entity body to obtain the HTML sent by the server.

For more information about HTTP content encoding refer to RFC 2616.

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