通过ajax发送八位字节流

时间:2016-04-30 17:12:46

标签: javascript php ajax

我通过ajax将八位字节流发送到我的PHP服务器。我希望将它作为八位字节流接收并解码,而不是字符串。问题是请求体是一个字符串,似乎ajax将它作为纯文本发送,即使我已经覆盖了mime类型。这是我的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

请求标头:

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 :)

所以mime类型是octet-stream,但请求有效负载是一个字符串。怎么了?

0 个答案:

没有答案
相关问题