【问题标题】:ERR_INVALID_HTTP_RESPONSE on nodejs http2nodejs http2上的ERR_INVALID_HTTP_RESPONSE
【发布时间】:2018-01-15 01:21:37
【问题描述】:

在使用 node new 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);

【问题讨论】:

    标签: node.js http2


    【解决方案1】:

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

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

    然后它起作用了。

    【讨论】:

      猜你喜欢
      • 2016-05-28
      • 2021-01-29
      • 2018-05-13
      • 2023-04-01
      • 2018-09-03
      • 2017-05-07
      • 2017-07-03
      • 2017-11-03
      • 2016-11-13
      相关资源
      最近更新 更多