nodejs发送arraybuffer给客户端的问题
发布于 4 个月前 作者 laoqiren 566 次浏览 来自 问答

我用nodejs发送arraybuffer数据给客户端,但是遇到了问题: server.js:

       var typedBuffer = new Uint8Array([1,8,6]);
        var myBuffer = new Buffer(typedBuffer)
        res.write(myBuffer);
        res.writeHead(200,{'Access-Control-Allow-Origin':'*','Access-Control-Allow-Method':'GET,POST','Content-Type':'application/octet-stream','Transfer-Encoding': 'chunked'});
        
        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([data]);
                var reader = new FileReader();
                reader.readAsBinaryString(blo);
                reader.onload = function(f){
                    console.log(this.result);
                }
            }
        }
	但是chrome报错:http://localhost:8008/ net::ERR_INVALID_CHUNKED_ENCODING,这是怎么回事呢?
1 回复

怎么没人回答呢

回到顶部