Gut*_*Mac 5 c++ rest json poco-libraries
我一直在研究如何做到这一点,所有的例子都是text/html.我已经尝试使用带有POCO C++网络库的JSON实现服务器api休息,但我不确定这是否是正确的方法.
void MyHandler::handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
response.setStatus(HTTPResponse::HTTP_OK);
response.setContentType("application/json");
std::ostream& ostr = response.send();
string send("true");
ostr << send;
response.setContentLength(send.size());
}
Run Code Online (Sandbox Code Playgroud)
最初它是为hmtl连接实现的:
void MyHandler::handleRequest(HTTPServerRequest& request, HTTPServerResponse& response)
{
response.setStatus(HTTPResponse::HTTP_OK);
response.setContentType("text/html");
std::ostream& ostr = response.send();
ostr << "<html><head><title>HTTPTimeServer powered by POCO C++ Libraries</title>";
ostr << "<body><p style=\"text-align: center; font-size: 48px;\">";
ostr << "ConfigHandler";
ostr << "</p></body></html>";
}
Run Code Online (Sandbox Code Playgroud)
我是否正确地完成了更改或者我错过了什么?
如果有人知道如何使用带有POCO C++库的JSON构建API REST的教程,我们将非常感激.
提前致谢.
| 归档时间: |
|
| 查看次数: |
5034 次 |
| 最近记录: |