我知道了。好像我的http- / content-headers被弄乱了。正确的标题应该是:
stream.write(("HTTP/1.0 200 OK\r\n" +
"Server: iRecon\r\n" +
"Connection: close\r\n" +
"Max-Age: 0\r\n" +
"Expires: 0\r\n" +
"Cache-Control: no-store, no-cache, must-revalidate, pre-check=0, post-check=0, max-age=0\r\n" +
"Pragma: no-cache\r\n" +
"Content-Type: multipart/x-mixed-replace; " +
"boundary=" + boundary + "\r\n" +
"\r\n" +
"--" + boundary + "\r\n").getBytes());
和
stream.write(("Content-type: image/jpeg\r\n" +
"Content-Length: " + buffer.size() + "\r\n" +
"X-Timestamp:" + timestamp + "\r\n" +
"\r\n").getBytes());
buffer.writeTo(stream);
stream.write(("\r\n--" + boundary + "\r\n").getBytes());
当然,将边界置于何处是您自己的选择。也可能有些字段是可选的(例如,大多数在Cache- Control中),但这是可行的,直到现在,我还是懒得剥夺它们。重要的是要记住换行符(\r\n
thingies)…