Using jpcap to capture html
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 thi开发者_JAVA百科sPacket = 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
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.
精彩评论