我正在尝试将压缩字符串发送到来自Flash AS3的node.js express服务器。在AS3中,我有类似的东西:
// AS3 Code
function save(data:ByteArray, theURL:String, compress:Boolean):void {
if (compress == true)
{
data.compress();
}
try
{
var request:URLRequest=new URLRequest(theURL);
request.data= data;
request.method=URLRequestMethod.POST;
request.contentType = "application/octet-stream";
var loader:URLLoader = new URLLoader();
loader.load(request);
}
catch (ex)
{
}
}
像这样测试:
save("This is a test string", "http://example.com/flash/", true);
节点代码
app.post('/flash/', bodyParser.raw({limit: '5mb'}), function(req,res){
console.log(req.body);
zlib.gunzip(req.body, function(err, unzipped_body){
if (!err)
{
console.log(unzipped_body);
}
console.log(err);
});
});
req.body最终在其中有一个字节缓冲区,但是当我尝试zlib.gunzip时,我得到一个不正确的标题检查。
<Buffer 78 da 0b c9 c8 2c 56 00 a2 dc 4a 85 94 c4 92 44 00 2a 56 05 55>
x?♂??,V ??J??ED *V♣U
{ [Error: incorrect header check] errno: -3, code: 'Z_DATA_ERROR' }
如果我不在as3中执行data.compress(),那么Node中的req.body会显示原始字符串。我对zlib压缩,节点或其他什么不了解? :)
答案 0 :(得分:0)
原来它应该是zlib.unzip而不是zlib.gunzip。我想as3 compress()函数不是“gzip”格式而是“zlib”格式?