繁体   English   中英

nodejs http2上的ERR_INVALID_HTTP_RESPONSE

[英]ERR_INVALID_HTTP_RESPONSE on nodejs http2

使用节点新的http2服务器时,尝试从浏览器ERR_INVALID_HTTP_RESPONSE调用时遇到此错误。

编码:

const http2 = require('http2');

// Create a plain-text HTTP/2 server
const server = http2.createServer();

server.on('stream', (stream, headers) => {
  console.log('headers: ', headers);
  stream.respond({
    'content-type': 'text/html',
    ':status': 200
  });
  stream.end('<h1>Hello World</h1>');
});

server.listen(80);

事实证明,chrome不允许您访问不安全的http2服务器,我不得不将代码更改为:

const server = http2.createSecureServer({
  key,
  cert
});

然后它起作用了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM