将二进制数据发送到服务器

I create an array buffer containing some data:

var myArray = new ArrayBuffer(512);
var longInt8View = new Uint8Array(myArray);
for (var i = 0; i < longInt8View.length; i++) {
    longInt8View[i] = i % 255;
}

And I send it so a server via POST:

if (window.XMLHttpRequest) {
    var xmlhttp = new XMLHttpRequest();
} else {
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function () {
    if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
        action(xmlhttp.responseText);
    }
};
xmlhttp.open("POST", 'http://somedomain.com:8080', true);
xmlhttp.send(myArray);
var action = function (response) {
    console.log(response);
};

I now want to receive these binary data in go code, and do something with it. How can I do this?

package main

import (
        "fmt"
        "net/http"
)

func handleRequest(w http.ResponseWriter, r *http.Request) {
        w.Header().Set("Access-Control-Allow-Origin", "*")
        w.Header().Set("Access-Control-Allow-Headers", "*")
        w.Header().Set("Content-Type", "text/plain")
        fmt.Fprintf(w, "%s", r.Body)
}

func main() {
        http.HandleFunc("/", handleRequest)
        http.ListenAndServe(":8080", nil)
}

I can see a reference to a memory block inside the body, but how do I get this specificaly?

Don't send binary data over HTTP protocol. Convert them in Base64. Send them as a normal string. Decode them from Base64 to binary on the server side.

To convert a binary data to base64 you can use the function btoa