I send an octet-stream via ajax to my PHP server. I want to receive it as the octet stream and decode it, not as a string. The thing is that the request body is a string, and it seems that ajax sends it as plain text, even though I have overriden the mime type. This is my ajax:
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == XMLHttpRequest.DONE ) {
if(xmlhttp.status == 200){
console.log(xmlhttp);
}
else if(xmlhttp.status == 400) {
alert('There was an error 400')
}
else {
alert('something else other than 200 was returned')
}
}
};
xmlhttp.open("POST", "something.php", true);
xmlhttp.overrideMimeType("application/octet-stream");
xmlhttp.send(stream); // some array buffer
The request headers:
Request Method:POST
Status Code:200 OK
Remote Address:[::1]:80
Response Headers
view source
Connection:Keep-Alive
Content-Length:175
Content-Type:application/octet-stream
Date:Sat, 30 Apr 2016 17:07:04 GMT
Keep-Alive:timeout=5, max=99
Server:Apache/2.4.18 (Win32) OpenSSL/1.0.2e PHP/7.0.4
X-Powered-By:PHP/7.0.4
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:pl-PL,pl;q=0.8,en-US;q=0.6,en;q=0.4
Cache-Control:max-age=0
Connection:keep-alive
Content-Length:160
Request Payload
@9a54dbc4bdd16c1a19804751d113c44b@Some very boring string here :)
So the mime type is octet-stream
, but the request payload is a string. What's wrong?