- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 Microsoft 的 cpprestsdk(又名 casablanca)开发 REST api,但在执行我的代码时我无法保持服务器运行。
在这里查看我的 main.cpp:
int main() {
cout << "Starting Server" << endl;
TransactionController server;
server.setEndpoint("http://0.0.0.0:4200/api");
server.initHandlers();
try {
server.openServer();
cout << "Server listening at: " << server.getEndpoint() << endl;
// figure out how to keep server running without this?
while (true);
}
catch(exception &e) {
cout << "--- ERROR DETECTED ---" << endl;
cout << e.what() << endl;
}
// this doesn't get reached bc of the while(true)
server.closeServer();
return 0;
}
此外,作为引用,这是我在 main.cpp 中的实现或功能:
pplx::task<void> TransactionController::openServer() {
return listener.open();
}
pplx::task<void> TransactionController::closeServer() {
return listener.close();
}
std::string TransactionController::getEndpoint() const{
return listener.uri().to_string();
}
void TransactionController::initHandlers() {
listener.support(methods::GET, bind(&TransactionController::handleGet, this, std::placeholders::_1));
listener.support(methods::POST, bind(&TransactionController::handlePost, this, placeholders::_1));
}
void TransactionController::setEndpoint(const string& value) {
listener = http_listener(value);
}
我发现了一个不太理想的解决方法,就是添加一个
while(true);
保持服务器运行,直到我手动停止执行。
不过,我想以更优雅的方式实现此功能。我浏览了在线文档,但未能找到正确的方法。
任何正确方向的提示或指示将不胜感激,因为我以前从未与卡萨布兰卡合作过。感谢您的宝贵时间!
最佳答案
所以我设法通过使用此处提供的代码来解决这个问题:
现在这是我的新 main.cpp:
int main() {
cout << "Starting Server" << endl;
InterruptHandler::hookSIGINT();
TransactionController server;
server.setEndpoint("http://0.0.0.0:4200/api");
server.initHandlers();
try {
server.openServer().wait();
cout << "Server listening at: " << server.getEndpoint() << endl;
InterruptHandler::waitForUserInterrupt();
server.closeServer().wait();
cout << "Shutting Down Server" << endl;
}
catch(exception &e) {
cout << "--- ERROR DETECTED ---" << endl;
cout << e.what() << endl;
}
return 0;
}
关于c++ - 如何保持服务器运行(cpprestsdk - 卡萨布兰卡),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49936203/
//Basic Authorization Setting http_client_config config; credentials creds(L"name", L"password"); co
我正在尝试将多部分数据发布到服务器,我正在从 CPR 切换到 CPPRestSDK,但我似乎找不到任何关于它的文档 来自 CPR,https://github.com/whoshuu/cpr 意思是我
我申请了ssl,但结果并不令人满意。使用wireshark查看时,服务器和客户端之间没有关键变化。 沟通是可能的,但并不令人满意。服务器是 Linux,客户端使用的是 Chrome。 我知道正常的 s
这将返回错误代码 401 或 500。有人可以帮助我哪里出错了吗? http_client client(L"https://oxford-speech.cloudapp.net/token/issu
我正在使用 Microsoft 的 cpprestsdk(又名 casablanca)开发 REST api,但在执行我的代码时我无法保持服务器运行。 在这里查看我的 main.cpp: int ma
我有一个任务需要一段时间才能执行,我想启动它并通过 Rest 请求广播它的进度 as described here .我已经使用 CPPRestSDK 设置了一个带有客户端进度轮询的监听器,但我想不出
我正在尝试使用 Microsoft's cpprestsdk ,但我收到此错误: HTTP Exception :: Failed to connect to any resolved endpoin
我有一个 api https://api.gm-system.net/api/authenticate/searchStaffs/searchText,它返回一个员工列表。 这里是我使用 cppres
我应该如何使用 cpprestsdk 处理分块响应?如何请求下一个 block ?那里是否有所需的功能? 这是我们执行 http 请求的方式: web::http::http_request requ
现在正在使用 WinHTTP,并希望切换到 cpprestsdk。我正在查看文档,但没有看到任何关于支持 NTLM/Negotiate/Kerberos 支持的信息。我错过了什么吗?我很难相信 MS
我在 Visual C++ 2013 中有一个 C++ 应用程序,它使用 cpprestsdk 从服务器获取信息。它工作正常(一个例子 here ) 现在,我正在使用外部第三方 API,这个 API
我已经访问了所有其他问题,但据我所知,没有一个是我的问题。 在 MacBook Pro 16GB 内存 Intel Core I7 上运行 OS X El Capitan 10.11.6 我也运行过
我正在尝试通过 [cpprestsdk][1] 实现证书固定,但到目前为止没有成功。 我在 http_client_config 对象内部看到我们可以调用方法 set_ssl_context_call
目标 构建一个简单的 cpprestsdk Visual Studio 中的示例。 到目前为止我做了什么 遵循 wiki 上的指南,我能够通过克隆 git 存储库来构建一个工作示例。但是,我希望能够自
我已经在 vs2017 中为 c++ 启动了新的 cmake 项目。并按照 cpprestsdk 说明在 Windows 上构建。 PM> vcpkg install cpprestsdk cppre
我正在将一个 Windows 项目移植到使用 cpprestsdk 的 CentOS Linux。我在 Windows 上使用 vcpkg,我想我会使用 vcpkg(和 cmake)引入和构建包,并将
我正在尝试使用 VS2017 为网络帖子 (REST) 构建一个 Linux 控制台应用程序。 我可以用 VS2017 为 linux 编译 cpprestsdk 吗? 最佳答案 当然可以。 使用“使
我尝试使用 cpprestsdk 向服务器发送 HTTP (REST) 请求。 void postRestRequest(const std::string& uri, const std::stri
我有一个在 Visual Studio 2019 中使用 cpprestsdk 的 dll 项目(以及用于测试目的的控制台应用程序)。在 Windows 7 和 Windows 10 上,原始包按预期
我使用 Mac,是 Xcode 和 C++ 的初学者。我使用 brew install cpprestsdk 安装了一个库。然后我将 Xcode 中的 header 搜索路径设置为 /usr/loca
我是一名优秀的程序员,十分优秀!