本文整理汇总了C++中http_request::get_arg方法的典型用法代码示例。如果您正苦于以下问题:C++ http_request::get_arg方法的具体用法?C++ http_request::get_arg怎么用?C++ http_request::get_arg使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http_request
的用法示例。
在下文中一共展示了http_request::get_arg方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: render_GET
void ModbusService::render_GET(const http_request& req, http_response** res)
{
//api/modbus/holdings/{connectorname}/{devaddress}/{baseaddress}/{count}
string connectorName = req.get_arg("connectorname");
string strDevAddress = req.get_arg("devaddress");
string strBaseAddress = req.get_arg("baseaddress");
string strCount = req.get_arg("value");
int devAddress = Converter::stoi(strDevAddress);
int baseAddress = Converter::stoi(strBaseAddress);
int count = Converter::stoi(strCount);
Document document;
StringBuffer buffer;
PrettyWriter<StringBuffer> wr(buffer);
Value jsonvalue;
IModbus* modbus = mm->Find(connectorName);
if (modbus!=NULL)
{
uint16_t* target = new uint16_t[count];
if (modbus->getHoldings(devAddress,baseAddress,count,target))
{
document.SetArray();
for(int i=0;i<count;i++)
{
Value jsonvalue;
jsonvalue.SetUint(target[i]);
document.PushBack(jsonvalue, document.GetAllocator());
}
}
else
{
document.SetObject();
jsonvalue.SetObject();
jsonvalue.SetString("Error",document.GetAllocator());
document.AddMember("Result",jsonvalue,document.GetAllocator());
jsonvalue.SetString("Modbus getHoldings failed",document.GetAllocator());
document.AddMember("Message",jsonvalue,document.GetAllocator());
}
delete[] target;
target = NULL;
}
else
{
document.SetObject();
jsonvalue.SetString("Error",document.GetAllocator());
document.AddMember("Result",jsonvalue,document.GetAllocator());
jsonvalue.SetString("Connector not found",document.GetAllocator());
document.AddMember("Message",jsonvalue,document.GetAllocator());
}
document.Accept(wr);
std::string json = buffer.GetString();
*res = new http_response(http_response_builder(json, 200,"application/json").string_response());
}
示例2: render_DELETE
void FoldersService::render_DELETE(const http_request& req, http_response** res)
{
if (req.get_user()=="a" && req.get_pass()=="a")
{
string strid = req.get_arg("id");
CUUID id = CUUID::Parse(strid);
HisDevFolder* folder = dynamic_cast<HisDevFolder*>(root->GetFolder()->Find(id));
if (folder!=NULL)
{
HisDevFolder* parentfolder = dynamic_cast<HisDevFolder*>(folder->GetParent());
parentfolder->Remove(id);
delete(folder);
root->Save();
*res = new http_string_response("", 200, "application/json");
return;
}
}
else
{
string message = "Autentication error";
*res = new http_string_response(message.c_str(), 401, "application/json");
return;
}
*res = new http_string_response("", 403, "application/json");
}
示例3: render_PUT
void ModbusService::render_PUT(const http_request& req, http_response** res)
{
string connectorName = req.get_arg("connectorname");
string strDevAddress = req.get_arg("devaddress");
string strBaseAddress = req.get_arg("baseaddress");
string strValue = req.get_arg("value");
int devAddress = Converter::stoi(strDevAddress);
int baseAddress = Converter::stoi(strBaseAddress);
int value = Converter::stoi(strValue);
Document document;
StringBuffer buffer;
PrettyWriter<StringBuffer> wr(buffer);
document.SetObject();
Value jsonvalue;
IModbus* modbus = mm->Find(connectorName);
if (modbus!=NULL)
{
if (modbus->setHolding(devAddress,baseAddress,value))
{
jsonvalue.SetString("OK",document.GetAllocator());
document.AddMember("Result",jsonvalue,document.GetAllocator());
}
else
{
jsonvalue.SetString("Error",document.GetAllocator());
document.AddMember("Result",jsonvalue,document.GetAllocator());
jsonvalue.SetString("Modbus setHolding failed",document.GetAllocator());
document.AddMember("Message",jsonvalue,document.GetAllocator());
}
}
else
{
jsonvalue.SetString("Error",document.GetAllocator());
document.AddMember("Result",jsonvalue,document.GetAllocator());
jsonvalue.SetString("Connector not found",document.GetAllocator());
document.AddMember("Message",jsonvalue,document.GetAllocator());
}
document.Accept(wr);
std::string json = buffer.GetString();
*res = new http_response(http_response_builder(json, 200,"application/json").string_response());
}
示例4: render
//using the render method you are able to catch each type of request you receive
void cat_resource::render(const http_request& req, http_response** res)
{
string file = req.get_arg("file");
cout << "file: " << file << endl;
//it is possible to send a response initializing an http_string_response
//that reads the content to send in response from a string.
*res = new http_response(http_response_builder(file, 200).file_response());
}
示例5: render
//using the render method you are able to catch each type of request you receive
void hello_world_resource::render(const http_request& req, http_response** res)
{
//it is possible to store data inside the resource object that can be altered
//through the requests
std::cout << "Data was: " << data << std::endl;
std::string datapar = req.get_arg("data");
set_some_data(datapar == "" ? "no data passed!!!" : datapar);
std::cout << "Now data is:" << data << std::endl;
//it is possible to send a response initializing an http_string_response
//that reads the content to send in response from a string.
*res = new http_response(http_response_builder("Hello World!!!", 200).string_response());
}
示例6: render_PUT
void FoldersService::render_PUT(const http_request& req, http_response** res)
{
if (req.get_user()=="a" && req.get_pass()=="a")
{
string strid = req.get_arg("id");
string content = req.get_content();
if (UpdateFolder(strid,content))
{
*res = new http_string_response("", 200, "application/json");
return;
}
}
else
{
string message = "Autentication error";
*res = new http_string_response(message.c_str(), 401, "application/json");
return;
}
*res = new http_string_response("", 403, "application/json");
}
示例7: render_GET
void FoldersService::render_GET(const http_request& req, http_response** res)
{
Document respjsondoc;
respjsondoc.SetArray();
string strid = req.get_arg("id");
HisDevFolder* folder = root->GetFolder();
string path = req.get_path();
if(!strid.empty())
{
CUUID id = CUUID::Parse(strid);
folder = dynamic_cast<HisDevFolder*>(folder->Find(id));
}
if (path.find("/api/folders")!=string::npos)
{
if (folder!=NULL)
{
FoldersToJson(folder,respjsondoc);
}
}
else if (path.find("/api/folder")!=string::npos)
{
if (folder!=NULL)
{
FolderToJson(folder,respjsondoc);
}
}
StringBuffer buffer;
PrettyWriter<StringBuffer> wr(buffer);
respjsondoc.Accept(wr);
std::string json = buffer.GetString();
*res = new http_string_response(json, 200, "application/json");
}
示例8: render_POST
void render_POST(const http_request& req, http_response** res)
{
*res = new http_string_response(
req.get_arg("arg1")+req.get_arg("arg2"), 200, "text/plain"
);
}