[英]ERR_INVALID_HTTP_RESPONSE on nodejs http2
When using node new http2 server, I encountered this error when attempting to call it from the browser: ERR_INVALID_HTTP_RESPONSE. 使用节点新的http2服务器时,尝试从浏览器ERR_INVALID_HTTP_RESPONSE调用时遇到此错误。
The code: 编码:
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);
Turns out, chrome won't allow you to access insecure http2 servers, I had to change the code to: 事实证明,chrome不允许您访问不安全的http2服务器,我不得不将代码更改为:
const server = http2.createSecureServer({
key,
cert
});
and then it worked. 然后它起作用了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.