I am attempting to use AJAX to send a byte array to the server:
$.ajax({
url: armd.scieldan.server + "/detachedSignFile/",
timeout: 120000,
type: "POST",
data: byteArray,
responseType: 'arraybuffer',
success: function(response) {
console.log("Sign: " + response);
},
error: function() {
console.log("error");
}
});
However, when trying to extract that array from httpExchange
, the content of requestBody
appears to be empty:
public void handle(HttpExchange httpExchange) throws IOException {
httpExchange.getResponseHeaders().set("Content-Type", "text/plain");
InputStream requestBody = httpExchange.getRequestBody();
byte[] receivedBytes = IOUtils.toByteArray(requestBody);
}
https://i.sstatic.net/0txFz.png
It seems that a BufferedInputStream
is present inside the requestBody
, but I am unable to access it. Is there a way to properly pass the byte array through JSON to HttpExchange
?