为HTTPS查询返回简单字符串的c++库
C++ library to send back simple string for HTTPS queries
我有一个用c++写的模拟器程序,运行在Ubuntu 12.04上。运行程序需要一些设置和选项,这些设置和选项由main的参数给出。我需要从远程机器/移动设备通过HTTPS查询这些选项(所以基本上想象我想返回main的参数)。我想知道是否有人能帮我。
应该有一些库来解决这个问题,比如Poco。我不确定它是否适合我的情况,但这里是poco中连接设置的任何示例。并不是必须才能使用任何库;这是最有效/最简单的方法。
Mongoose(或非gpl分支Civetweeb)是嵌入式web服务器。非常容易为
设置和添加控制器(通常是六行代码)只需将项目文件(1c文件)添加到您的项目和构建中,添加一行来启动服务器侦听并为其提供您喜欢的选项,并添加回调函数来处理请求。它可以开箱使用ssl(尽管IIRC也需要安装openssl)
有另一个答案SO与一些比较。我在工作中使用了civetweb,并且对它的简单性印象深刻。不过没有太多的文档。
这是一个简化的POCO版本,完整的代码参见HTTPSTimeServer示例。
struct MyRequestHandler: public HTTPRequestHandler
{
void handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
response.setContentType("text/html");
// ... do your work here
std::ostream& ostr = response.send();
ostr << "<html><head><title>HTTPServer example</title>"
<< "<body>Success!</body></html>";
}
};
struct MyRequestHandlerFactory: public HTTPRequestHandlerFactory
{
HTTPRequestHandler* createRequestHandler(const HTTPServerRequest& request)
{
return new MyRequestHandler;
}
};
// ...
// set-up a server socket
SecureServerSocket svs(port);
// set-up a HTTPServer instance (you may want to new the factory and params
// prior to constructing object to prevent the possibility of a leak in case
// of exception)
HTTPServer srv(new MyRequestHandlerFactory, svs, new HTTPServerParams);
// start the HTTPServer
srv.start();