I have a byte array in front-end generated by javascript that I want to send to java servlet through ajax. How can I do that?
Asked
Active
Viewed 198 times
0
-
https://stackoverflow.com/questions/19959072/sending-binary-data-in-javascript-over-http – lance-java Nov 30 '18 at 07:48
1 Answers
0
See this q&a which discusses a jquery solution but also offers a vanilla js solution
var bytesToSend = [253, 0, 128, 1],
bytesArray = new Uint8Array(bytesToSend);
var xhr = new XMLHttpRequest();
xhr.open('POST', '%your_service_url%');
xhr.setRequestHeader('Content-Type', 'application/octet-stream');
xhr.send(bytesArray);
lance-java
- 23,463
- 3
- 50
- 89