请问一下,我使用httplib.h创建http服务器时,在vs2022和vs2017上使用都正常,但是在vs2015上使用则报错,get请求不会报错,post请求报错,httplib.h是不能再vs2015上使用post请求吗:
严重性 代码 说明 项目 文件 行
错误(活动) 有多个 重载函数 "httplib::Server::Post" 实例与参数列表匹配: Project8 c:\Users\xhn\Documents\Visual Studio 2015\Projects\Project8\Project8\源.cpp 33
严重性 代码 说明 项目 文件 行
错误 C2668 “httplib::Server::Post”: 对重载函数的调用不明确 Project8 c:\Users\xhn\documents\visual studio 2015\Projects\Project8\Project8\源.cpp 64
严重性 代码 说明 项目 文件 行
错误(活动) 有多个 重载函数 "httplib::Server::Post" 实例与参数列表匹配: Project8 c:\Users\xhn\Documents\Visual Studio 2015\Projects\Project8\Project8\源.cpp 66
严重性 代码 说明 项目 文件 行
错误 C2668 “httplib::Server::Post”: 对重载函数的调用不明确 Project8 c:\Users\xhn\documents\visual studio 2015\Projects\Project8\Project8\源.cpp 105
#include "httplib.h"
#include <iostream>
using namespace std;
class ServerSet {
public:
std::string host_nickname;
std::string client_ip_id;
std::string client_port;
std::string server_ip;
std::string server_port;
};
int main(void)
{
ServerSet server;
using namespace httplib;
Server svr;
svr.Get(R"(/HostInfo/setOsColl/(\d+))", [&](const Request& req, Response& res) {
auto numbers = req.matches[1];
std::cout << numbers << std::endl;
if (numbers != "0" && numbers != "1") {
res.set_content("false", "text/plain");
}
else {
res.set_content("true", "text/plain");
}
});
svr.Post("/HostInfo/setAgentIp", [&](const Request& req, Response& res) {
std::cout << req.body << std::endl;
string body = req.body;
auto client_ip_id = req.get_param_value("client_ip_id");
auto client_port = req.get_param_value("client_port");
std::regex regex("\"([^\"]+)\":\\s*\"([^\"]*)\"");
std::smatch match;
std::sregex_iterator iter(body.begin(), body.end(), regex);
std::sregex_iterator end;
while (iter != end)
{
std::string field_name = iter->str(1);
std::string field_value = iter->str(2);
if (field_name == "client_ip_id")
{
server.client_ip_id = field_value;
}
else if (field_name == "client_port")
{
server.client_port = field_value;
}
++iter;
}
std::cout << "client_ip_id: " << server.client_ip_id << std::endl;
std::cout << "client_port: " << server.client_port << std::endl;
res.set_content("true", "text/plain");
});
svr.Post("/HostInfo/setServerIp", [&](const Request& req, Response& res) {
std::cout << req.body << std::endl;
string body = req.body;
std::regex regex("\"([^\"]+)\":\\s*\"([^\"]*)\"");
std::smatch match;
std::string host_nickname;
std::string server_ip;
std::string server_port;
std::sregex_iterator iter(body.begin(), body.end(), regex);
std::sregex_iterator end;
while (iter != end)
{
std::string field_name = iter->str(1);
std::string field_value = iter->str(2);
if (field_name == "host_nickname")
{
server.host_nickname = field_value;
}
else if (field_name == "server_ip")
{
server.server_ip = field_value;
}
else if (field_name == "server_port")
{
server.server_port = field_value;
}
++iter;
}
std::cout << "host_nickname: " << server.host_nickname << std::endl;
std::cout << "server_ip: " << server.server_ip << std::endl;
std::cout << "server_port: " << server.server_port << std::endl;
res.set_content("true", "text/plain");
});
svr.listen("0.0.0.0", 8002);
}