【发布时间】:2021-09-21 14:11:05
【问题描述】:
我正在使用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;
}
当我尝试在http://localhost:8080 上打开浏览器(Chrome 或 Firefox)时,出现以下错误:
此页面无法正常工作
localhost 没有发送任何数据。
ERR_EMPTY_RESPONSE
即使我尝试使用curl,它也会给我错误:
curl: (52) 来自服务器的空回复
唯一有效的是curl http://localhost:8080 --http2-prior-knowledge。
有解决办法吗?
【问题讨论】: