2

I want to use Node.js to return arrayBuffer to the client, but I found some problems.

my node server.js:

res.write(new Buffer([0,1,2]));
res.writeHead(200,{'Access-Control-Allow-Origin':'*','Access-Control-Allow-Method':'GET,POST','Content-Type':'application/octet-stream'});
res.end();

and my client code:

var xhr = new XMLHttpRequest();
xhr.responseType = "arraybuffer";
xhr.open("post","http://localhost:8008/");
xhr.onload = function(data){
    if (xhr.status === 200) {
        console.log('succuess');
        console.log(typeof this.response);
    }
}

but the chrome console error:

POST http://localhost:8008/ net::ERR_INVALID_CHUNKED_ENCODING
Alex M
  • 2,472
  • 7
  • 25
  • 32
laoqiren
  • 2,375
  • 4
  • 15
  • 26

0 Answers0