接收和解释hex数据时发生内容types为application / octet-stream错误

我正尝试将二进制数据发送到Azure移动服务API。 当我们收到请求并尝试parsing数据时,高于7f的字节值(即80,81,90,ff等)被解释为不同。 例如,如果我们已经发送

Sent data : 67 01 00 00 31 00 31 00 32 00 31 00 00 00 A0 10 Received data: 67 01 00 00 31 00 31 00 32 00 31 00 00 00 ef bf bd 10 

这是curl命令:

 curl --header "Content-Type:application/octet-stream" -X POST https://xxxx/Api/temp --data-binary @/home/device_data.txt 

Nodejs移动服务脚本代码片段

 exports.post = function(request, response) { var payload=new Buffer(request.body); console.log(payload); } 

我怀疑我们的8位二进制stream被解释为7位字符stream。 有人可以请说一说吗?

request.body来自ExpressJS-在这里阅读: http : //expressjs.com/4x/api.html#req.body

你会注意到request.body不是请求的主体 – 它是一个parsing的主体。 因此,您可能需要明确使用body-parser来处理请求。

在这里看到另一个相同的事例 : POST中的nodejs / express和二进制数据

另外签出body-parser: https : //github.com/expressjs/body-parser#bodyparserrawoptions

不幸的是,我不相信你可以在移动服务案例中设置额外的中间件。 您可以做的一件事就是将您的应用程序转换到Azure应用程序服务移动应用程序 – 这需要一个常规ExpressJS应用程序,但通过SDK处理身份validation,推送通知和数据访问(请参阅https://github.com/Azure/azure -mobile-apps-node和介绍性博客文章: https : //azure.microsoft.com/en-us/blog/announcing-node-for-azure-mobile-apps/ )