我正在使用nghttp2_asio。我使用./configure --enable-asio-lib
. 然后,我添加/usr/local/lib
到/etc/ld.so.conf
文件中。代码如下:
#include "bits/stdc++.h"
#include "nghttp2/asio_http2_server.h"
using namespace std;
using namespace nghttp2::asio_http2;
using namespace nghttp2::asio_http2::server;
int main(int argc, char **argv) {
http2 srv;
srv.num_threads(4);
srv.handle("/", [](const request &req, const response &res) {
cout << req.uri().path << endl;
header_map headers;
headers.emplace("content-type", header_value{ "text/html", false });
res.write_head(200, headers);
res.end(file_generator("index.html"));
});
boost::system::error_code ec;
if (srv.listen_and_serve(ec, "localhost", "8080")) cerr << ec.message() << endl;
return 0;
}
当我尝试在 上打开浏览器(Chrome 或 Firefox)时http://localhost:8080
,出现以下错误:
此页面不工作
localhost没有发送任何数据。
ERR_EMPTY_RESPONSE
即使我尝试使用curl
,它也会给我错误:
curl:(52)来自服务器的空回复
唯一有效的是curl http://localhost:8080 --http2-prior-knowledge
.
有解决方案吗?