1

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

客户

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 数据?

4

2 回答 2

1

bodyParser 中间件不解析 POST 的二进制数据。当我尝试使用 base64 编码的字符串时,它会显示为 JSON 对象中的对象名称,类似于 {"data":},显然期望 POST-data 格式为 name=value。

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

这是使用没有 express 的 vanilla http 模块,但无论如何都应该工作。

于 2014-02-14T12:43:09.267 回答
0

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

于 2014-02-05T16:08:17.187 回答