Getting HTTP GET binary parameter in Play Framework

I need to get binary data in a GET request in the Play Framework. This is used to get info_hash from BitTorrent clients.

I get the following:

byte[] infoHash = params.get("info_hash").getBytes("ISO-8859-1")

Unfortunately, all non-ascii characters are replaced with 0x3f.

PS I can get url encoded parameters from Http.Request.current (). Querystring, but this is a bad idea.

Update: I redefine the method play.data.parsing.UrlEncodedParser.parse(InputStream is)with my option, which uses ISO-8859-1 in the parameter instead of hard-coded UTF-8, as in the original, and everything works as it should. But I'm still looking for a better way, because I don't want to edit the sources.

+3
source share
1 answer

http://wiki.theory.org/BitTorrent_Tracker_Protocol:

info_hash

20 sha1 bencoded metainfo.

SHA1 : 92a11182a8405cbd8d25cd3cc3334fc6155bec06

. , URL- info_hash.

, . , , . , :

byte[] decode(String enc) {
    if (enc.length() % 2 != 0) throw new NumberFormatException();

    byte arr[] = new byte[enc.length() / 2];
    int c = 0;
    for (int i = 0; i < enc.length(); i += 2) {
        arr[c++] = Integer.valueOf(enc.substring(i, i + 2), 16).byteValue();
    }
    return arr;
}
+1

Source: https://habr.com/ru/post/1789620/


All Articles