about using the HTTP protocol to transfer binary files

Source: Internet
Author: User
Tags base64

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.