缓冲区大小错误

时间:2018-10-26 19:21:20

标签: java android node.js

我正在尝试将android应用中的ByteBuffer发送到Node.JS服务器。

ByteBuffer的大小为680,但是在检查接收长度时,它较小(仅16个字节)。

我做错了什么?以及如何发送和接收整个ByteBuffer大小?

Android:

 ByteBuffer newBuffer = ByteBuffer.allocate(680);
 newBuffer.order(ByteOrder.BIG_ENDIAN);

...

URL obj = null;
obj = new URL(POST_URL);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Content-Type", "MultiPart/Form-Data");

// Send
con.setDoOutput(true);
OutputStream os = con.getOutputStream();
DataOutputStream dataOutputStream = new DataOutputStream(os);
dataOutputStream.write(bf.array());
dataOutputStream.flush();
dataOutputStream.close();  

在检查ByteBuffer时,就在发送之前,我看到:

pos = 0, lim = 680, capcity = 680

Node.JS端:

app.post('/addBinary.html', function (req, res) {   
    var buf = new Buffer(req.body.toString('binary'),'binary');
    log.info("Buffer Length: ", buf.length);
})

0 个答案:

没有答案