如何在后端使用nodejs + express处理ajax / http-post请求(responsetype:arraybuffer)

情况:客户端js向nodejs express服务器发送一个jjax请求。

客户

xmlHttpRequest=new XMLHttpRequest(); xmlHttpRequest.open("POST","/some/server/path,true); xmlHttpRequest.responseType="arraybuffer"; xmlHttpRequest.send(new Uint8Array(arraybufferobject)); 

服务器(到目前为止)

 var express = require('express'); var server = express(); server.use(express.static(__dirname)); server.use(express.bodyParser()); server.post('/goforms/modbus/',function(req,res,next){ //How to access the uint8array || arraybuffer ? }); server.listen(80); 

我坚持在这一点上。 如何访问HTTP POST数据?

bodyParser中间件不parsingPOSTed二进制数据。 当我尝试base64编码的string,它会显示为JSON对象中的对象名称,如{“data”:},显然期望在表单名称=值的POST数据。

可能有一个处理二进制数据的中间件,或者你可以通过绑定到“data”事件来访问原始数据,并使用ProtocolBuffers.js wiki中描述的方法将接收到的数据块堆叠到缓冲区中。

这是使用香草http模块没有明确expression,但应该无论如何工作。

我不知道arraybuffer,但通常我们可以使用req.body参数来访问POST数据。 那对你有用吗?

Interesting Posts