The HTTP protocol is character-based (ASCII), and when the Content-type entry is text/xml, the content is in text format, and in binary format, the Content-type item is image/gif. For example, the browser requests packet information for a picture:
1. Request message:
2. Response message:
The following is the binary data area
From the above, the content in the HTTP protocol can be pure binary.
Generally understood, the HTTP protocol requests, the corresponding is the ASCII character transmission, if wants to transmit the binary system to pass through the BASE64 or the mime and so on the code (because the HTTP protocol POP3, the SMTP mail protocol all is for the text, but FTP supports transmits the binary data, That does not need to be encoded into character data)
If you are using HTTP to transmit binary (without base64 encoding), you may be causing problems:
1) Do not know the specific length of the transmitted bytes, such as the type of int transferred, after converting int type to char, lost the length of the information, such as the number 1234567, originally only 4 bytes, but converted to text "1234567" is 7 bytes. In the int type is good to do, but an array of time, after conversion, in the conversion back is very troublesome.
2) for some numbers, the binary transport server cannot be processed. such as int 1, binary data is 0x00000001, by byte transmission time, the client can send normally, but Libevent received later, in the Libevent_http layer is thrown, will be truncated data, the first two 0x00 is the string of the stop character.
about using the HTTP protocol to transfer binary files