使用jpcap捕获html
当我发出 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于您可以读取 HTTP 标头,但无法读取 HTML 内容,因此我猜测 HTTP 响应的正文已被压缩(例如,使用 gzip)。您可以识别压缩响应,因为 HTTP 响应标头包含如下行:
如果您可以发布程序的示例输出,我们可以证实这一理论。在这种情况下,您应该使用解压缩实体主体来获取服务器发送的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:
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.