Chunked http decoding in java?

I will decrypt the http packets. And I ran into a problem related to the piece problem. When I receive the http packet, it has a header and a body. When the transcription is encoded, I do not know what to do?

Is there a useful API or class for decrypting data in JAVA?

And if someone experienced about decrypting http, please show me a way how to do this?

+5
source share
4 answers

Use a full-featured HTTP client, such as the Apache HttpComponents Client or only Java SE provided java.net.URLConnection( mini-tutorial here ). Both process it completely transparently and give you a "normal" InputStreamback. In turn, HttpClient also comes with ChunkedInputStreamwhich you just need to decorate InputStream.

If you really insist on a self-service library for this, I would suggest creating a type class ChunkedInputStream extends InputStreamand writing the logic accordingly. You can find more information on how to analyze it in this Wikipedia article .

+11
source
+1

API, Jodd Http (http://jodd.org/doc/http.html). Chunked , .

:

HttpRequest httpRequest = HttpRequest.get("http://jodd.org");
HttpResponse response = httpRequest.send();

System.out.println(response);
+1

, , Oracle JRE:

private static byte[] unchunk(byte[] content) throws IOException {
    ByteArrayInputStream bais = new ByteArrayInputStream(content);
    ChunkedInputStream cis = new ChunkedInputStream(bais, new HttpClient() {}, null);
    return readFully(cis);
}

sun.net.www.http.ChunkedInputStream, java.net.HttpURLConnection, .

This implementation does not provide detailed exceptions (line numbers) in the wrong content format.

It works with Java 8, but may fail with the next version. You have been warned.

May be useful for prototyping.

You can choose any implementation readFullyfrom Convert InputStream to Byte Array in Java .

+1
source

All Articles