문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top