Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ssl/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用libhttpserver构建https服务器_C++_Ssl_Https_Httpserver - Fatal编程技术网

C++ 使用libhttpserver构建https服务器

C++ 使用libhttpserver构建https服务器,c++,ssl,https,httpserver,C++,Ssl,Https,Httpserver,我试图编译下面的代码来运行一个基本的https服务器,但遇到了一个无法解决的错误。类hello_world_resource负责服务器的启动,return语句给出服务器在被访问时应该给出的响应 服务器的url由函数“register\u resource”定义 库的github文档的url- 我已经多次尝试下载ssl和curl,并搜索了谷歌,但我仍然无法找到这个问题的原因 abcd.key和xyz.crt是我按照此过程在线生成的自签名证书- #包括 使用名称空间httpserver; 类hel

我试图编译下面的代码来运行一个基本的https服务器,但遇到了一个无法解决的错误。类hello_world_resource负责服务器的启动,return语句给出服务器在被访问时应该给出的响应

服务器的url由函数“register\u resource”定义

库的github文档的url-

我已经多次尝试下载ssl和curl,并搜索了谷歌,但我仍然无法找到这个问题的原因

abcd.key和xyz.crt是我按照此过程在线生成的自签名证书-

#包括
使用名称空间httpserver;
类hello\u world\u资源:公共http\u资源
{
公众:
const std::共享ptr呈现(const http\u请求&)
{
返回std::shared_ptr(新
字符串_响应(“你好,世界!”);
}
};
int main()
{
Web服务器ws=创建Web服务器(8080)
.use_ssl()
.https_mem_key(“/path/to/abcd.key”)
.https_mem_cert(“/path/to/xyz.crt”);
你好,世界资源中心;
ws.register_资源(“/hello”,&hwr);
ws.start(true);
返回0;
}
引发的错误是:

在抛出“std::invalid_参数”的实例后调用terminate 什么():BD A. (G)BBJ 中止


代码应该运行,服务器应该在-

哪个语句引发异常?尝试用
Try catch
语句包围代码,并显示异常消息。@Clonk我尝试过了,得到的回复是我在“what()”之后写的回复@KaranMotiramani我刚刚在本地编译了您的代码,并使用您发布的链接生成了密钥和证书(这是相当标准的)。它对我有效。您是否确保运行服务器的用户对您的密钥文件具有读取权限?Openssl仅为所有者使用“rw”权限生成这些文件,如果您使用“sudo”生成这些文件,则将是root。哪个语句引发异常?请尝试使用
Try catch
语句和异常消息是如何产生的。@Clonk我试过了,得到的Response是我在“what()”之后写的@Karamotiramani我刚刚在本地编译了你的代码,并使用你发布的链接生成了密钥和证书(这是相当标准的)。它对我有效。您是否确保运行服务器的用户对您的密钥文件具有读取权限?Openssl仅为所有者使用“rw”权限生成密钥文件,如果您使用“sudo”生成密钥文件,则将是root。
#include <httpserver.hpp>
using namespace httpserver;

class hello_world_resource : public http_resource 
{
    public:
    const std::shared_ptr<http_response> render(const http_request&) 
    {
        return std::shared_ptr<http_response>(new 
        string_response("Hello, World!"));
    }
};

int main() 
{
     webserver ws = create_webserver(8080)
         .use_ssl()
         .https_mem_key("/path/to/abcd.key")
        .https_mem_cert("/path/to/xyz.crt");

        hello_world_resource hwr;
        ws.register_resource("/hello", &hwr);
        ws.start(true);

    return 0;
}