0
我正在試驗HTTP/2。我在this repo中發現了一些例子。這裏的構造函數(樣板代碼跳過):Jetty的HTTP/2問題 - 無效的前言
public WebServer(String path, HttpServlet servlet, int port) {
Server server = new Server(new QueuedThreadPool());
ServletContextHandler context = new ServletContextHandler(server, "/", ServletContextHandler.SESSIONS);
context.addServlet(new ServletHolder(servlet), path);
ServerConnector connector = new ServerConnector(server, 1,1, new HTTP2ServerConnectionFactory(new HttpConfiguration()));
connector.setPort(port);
server.addConnector(connector);
}
然後我start()
服務器,運行java http2客戶端從上面回購所提到的,它並沒有錯誤連接。但後來我嘗試做相同的捲曲度:
# curl --http2 http://localhost:8080
invalid_preface
而且瀏覽器(Chrome)說:
GET http://localhost:8080/ net::ERR_INVALID_HTTP_RESPONSE
什麼whong與服務器?
感謝您對瀏覽器限制的解釋。但是,如果我使用curl的'--http2'標誌,它會失敗並顯示相同的消息。 – awfun
'curl'對我來說不會失敗。也許你有一箇舊版本的'curl',或者舊版本的'openssl'等等。你需要確保你的'curl'版本在HTTP/2下正常工作,如果你仍然有錯誤,請發佈完整的服務器日誌和客戶端日誌。 – sbordet