Retrieving binary data with XMLHttpRequest

Using XMLHttpRequest to fetch binary data from a HTTP source is “problematic”, as you can find with a simple websearch.

But what exactly means “problematic” in this context?

I gave it a try with Firefox and found out that every byte above 0x7f is translated into 0xfd. In other words: Plain old ASCII is left alone, everything above it results in a fixed value of 0xfd. Guess this has to do with the stream being interpreted as UTF-8 text…

A hex dump of a binary range [00 .. ff], retrieved through XMLHttpRequest:

joe$ od -t x1 -v xhrsweep.bin 
0000000    00  01  02  03  04  05  06  07  08  09  0a  0b  0c  0d  0e  0f
0000020    10  11  12  13  14  15  16  17  18  19  1a  1b  1c  1d  1e  1f
0000040    20  21  22  23  24  25  26  27  28  29  2a  2b  2c  2d  2e  2f
0000060    30  31  32  33  34  35  36  37  38  39  3a  3b  3c  3d  3e  3f
0000100    40  41  42  43  44  45  46  47  48  49  4a  4b  4c  4d  4e  4f
0000120    50  51  52  53  54  55  56  57  58  59  5a  5b  5c  5d  5e  5f
0000140    60  61  62  63  64  65  66  67  68  69  6a  6b  6c  6d  6e  6f
0000160    70  71  72  73  74  75  76  77  78  79  7a  7b  7c  7d  7e  7f
0000200    fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd
0000220    fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd
0000240    fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd
0000260    fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd
0000300    fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd
0000320    fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd
0000340    fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd
0000360    fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd  fd
0000400