![](/img/trans.png)
[英]GET http://localhost:3306/socket.io/?EIO=3&transport=polling&t=NQfLxAy net::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.