Sobes.tech
Junior — Middle

Is it possible to transmit binary data over the HTTP/1.1 protocol?

sobes.tech AI

Answer from AI

Yes, binary data can be transmitted via the HTTP/1.1 protocol. HTTP does not restrict the type of data transmitted — the request and response bodies can contain any bytes. To correctly transmit binary data, a corresponding Content-Type header is usually specified, such as application/octet-stream or a specific file MIME type (e.g., image/png).

Example of transmitting binary data in Go:

resp, err := http.Get("https://example.com/image.png")
if err != nil {
    log.Fatal(err)
}
defer resp.Body.Close()

// Read binary data from the response body
data, err := io.ReadAll(resp.Body)
if err != nil {
    log.Fatal(err)
}

// data contains the binary content of the file

Thus, HTTP/1.1 fully supports the transmission of binary data without additional encoding.

Is it possible to transmit binary data over the… - sobes.tech