0

我的js代码:

http.createServer(function (req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.write("sending two files"+"      ");
    res.writeHead(200, {'Content-Type', "video/mp4"});
    var stream = GridFile.stream(true);
    stream.pipe(res);
    res.end();
}).listen(3001, "ipaddress"); 

我正在从 js 文件的一个回调函数中发送两种 MIME 类型(文本/纯文本、视频/mp4)。如何在 html 中检索和解析相同的类型?

谁能帮我解决这个问题...

4

1 回答 1

0

你需要做这样的事情,但同样,我不知道你为什么想要:

var CRLF = '\r\n';
http.createServer(function (req, res) {
  var BOUNDARY = '' + Date.now();
  res.writeHead(200, {'Content-Type': 'multipart/mixed; boundary=' + BOUNDARY });
  res.write(
    CRLF +
    '--' + BOUNDARY + CRLF +
    'Content-Type: text/html' + CRLF +
    CRLF
  );
  res.write('<html><body><p>This is the first file</p></body></html>');
  res.write(
    CRLF +
    '--' + BOUNDARY + CRLF +
    'Content-Type: video/mp4' + CRLF +
    CRLF
  );
  var stream = GridFile.stream(true);
  steam.on('end', function () {
    res.write(
      CRLF +
      '--' + BOUNDARY + '--' +
      CRLF
    )
  })
  stream.on('error', function (e) {
    console.log('stream error', e)
    res.end()
  })
  stream.pipe(res, { end: false })
}).listen(3001, "ipaddress"); 
于 2016-06-16T20:46:00.427 回答