我想通过node返回arraybuffer给客户端,但是遇到了问题:
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();
客户端代码:
var xhr = new XMLHttpRequest();
xhr.responseType = "arraybuffer";
xhr.open("post","http://localhost:8008/");
xhr.onload = function(data){
if(xhr.status === 200){
console.log('succuess');
var blo = new Blob(this.response);
var reader = new FileReader();
reader.readAsBinaryString(blo);
reader.onload = function(f){
console.log(this.result);
}
}
}
但是chrome控制台并没有打印结果,而是输出错误:
POST http://localhost:8008/ net::ERR_INVALID_CHUNKED_ENCODING
请问这是怎么回事呢,谢谢aaa
至尊宝的传说
相关分类