作者:Quiet静以修身 | 来源:互联网 | 2023-05-19 06:04
Usinghttps:github.comdcodeIOProtoBuf.jsIencodedamessageIwanttosendtoajavaserverto
Using https://github.com/dcodeIO/ProtoBuf.js/ I encoded a message I want to send to a java server to a ByteBuffer called batch:
使用https://github.com/dcodeIO/ProtoBuf.js/ I对我想要发送给java服务器的名为batch的ByteBuffer的消息进行编码:
batch:
ByteBuffer {array: ArrayBuffer, view: DataView, offset: 0, markedOffset: -1, length: 139…}
array: ArrayBuffer
length: 139
littleEndian: false
markedOffset: -1
offset: 0
view: DataView
__proto__: Object
Now I want to send this with jquery's Ajax:
现在我想用jquery的Ajax来发送这个:
$.ajax({
url: myUrl,
type: 'POST',
data : batch,
contentType: 'application/protobuf',
accept: 'application/json'
})
But I can't seem to do this. The above code gives me the jquery exception:
但我似乎不能这么做。上面的代码给了我jquery异常:
Uncaught TypeError: Cannot set property 'littleEndian' of undefined myScript.js:1353
ByteBuffer.LE bunk.js:1353
jQuery.param.add jquery.js:7203
buildParams jquery.js:7261
jQuery.param jquery.js:7223
jQuery.extend.ajax
If I get an array buffer from batch (batch.toArrayBuffer()) the Java server gets nothing from
如果我从批处理(batch. toarraybuffer())获得一个数组缓冲区,那么Java服务器将一无所获
ByteStreams.toByteArray(req.getInputStream());
How should I encode the ByteBuffer to send like this? And how should I decode it into a java byte array?
如何对ByteBuffer进行编码,以便像这样发送?如何将它解码成java字节数组?
2 个解决方案