我正在尝试将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);
})