本文整理汇总了C++中http_request类的典型用法代码示例。如果您正苦于以下问题:C++ http_request类的具体用法?C++ http_request怎么用?C++ http_request使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了http_request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: handle_get
//
// A GET of the dealer resource produces a list of existing tables.
//
void BlackJackDealer::handle_get(http_request message)
{
ucout << message.to_string() << endl;
auto paths = http::uri::split_path(http::uri::decode(message.relative_uri().path()));
if (paths.empty())
{
message.reply(status_codes::OK, TablesAsJSON(U("Available Tables"), s_tables));
return;
}
utility::string_t wtable_id = paths[0];
const utility::string_t table_id = wtable_id;
// Get information on a specific table.
auto found = s_tables.find(table_id);
if (found == s_tables.end())
{
message.reply(status_codes::NotFound);
}
else
{
message.reply(status_codes::OK, found->second->AsJSON());
}
};
示例2: on_request
http_response www_server::on_request(const http_request &req) {
http_response resp;
// we are support only HTTP GET method
if (req.get_method() != http_method::get) {
resp.set_status(http_error::method_not_allowed);
resp.set_allow(http_method::get);
resp.set_content("The POST requests are not supported yet.");
return resp;
}
// obtain the name of the file requested
url u(req.get_path_info());
u.normalize(root_dir);
// load file content to the server response
try {
ifstream in(u.path.c_str());
// if file can't be open, throw an error
if (!in)
throw dbp::exception(string("File not found: ") + u.path);
// set file content type
resp.set_content_type(mime(u.path));
// load file
resp.add_content(in);
}
catch (dbp::exception &e) {
// return error message
resp.set_status(http_error::not_found);
resp.set_content(e.what());
}
return resp;
}
示例3: handle_get
// Handler to process HTTP::GET requests.
// Replies to the request with data.
void CasaLens::handle_get(http_request message)
{
auto path = message.relative_uri().path();
auto content_data = m_htmlcontentmap.find(path);
if (content_data == m_htmlcontentmap.end())
{
message.reply(status_codes::NotFound, U("Path not found")).then(std::bind(&handle_error, std::placeholders::_1));
return;
}
auto file_name = std::get<0>(content_data->second);
auto content_type = std::get<1>(content_data->second);
concurrency::streams::fstream::open_istream(file_name, std::ios::in).then([=](concurrency::streams::istream is)
{
message.reply(status_codes::OK, is, content_type).then(std::bind(&handle_error, std::placeholders::_1));
}).then([=](pplx::task<void>& t)
{
try
{
t.get();
}
catch(...)
{
// opening the file (open_istream) failed.
// Reply with an error.
message.reply(status_codes::InternalError).then(std::bind(&handle_error, std::placeholders::_1));
}
});
}
示例4: 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");
}
示例5: if
void details::http_listener_impl::handle_request(http_request msg)
{
// Specific method handler takes priority over general.
const method &mtd = msg.method();
if(m_supported_methods.count(mtd))
{
m_supported_methods[mtd](msg);
}
else if(mtd == methods::OPTIONS)
{
handle_options(msg);
}
else if(mtd == methods::TRCE)
{
handle_trace(msg);
}
else if(m_all_requests != nullptr)
{
m_all_requests(msg);
}
else
{
// Method is not supported.
// Send back a list of supported methods to the client.
http_response response(status_codes::MethodNotAllowed);
response.headers().add(U("Allow"), get_supported_methods());
msg.reply(response);
}
}
示例6: 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());
}
示例7: response
void
RestEngineUri::handle_delete(http_request request)
{
std::cout << request.method() << " : " << request.absolute_uri().path() << std::endl;
http_response response(status_codes::OK);
std::string resultstr("Not Supported");
std::pair<bool, std::string> result {true, std::string()};
make_response(response, resultstr, result);
request.reply(response);
}
示例8:
pplx::task<http_response> client::http_client::request(http_request request, pplx::cancellation_token token)
{
if(!request.headers().has(header_names::user_agent))
{
request.headers().add(header_names::user_agent, USERAGENT);
}
request._set_base_uri(base_uri());
request._set_cancellation_token(token);
return m_pipeline->propagate(request);
}
示例9: handle_get
void RDService::handle_get(http_request message)
{
std::cout << "GET request got" << std::endl;
web::uri reqUri = message.relative_uri();
wcout << "Query:" << reqUri.query() << endl << reqUri.resource().to_string() << endl;
utility::string_t queryStr = reqUri.query();
auto path = reqUri.path();
vector<utility::string_t> queryList = splitStringByAnd(queryStr);
wstring conditions = U("");
if (queryList.size() > 0)
{
conditions += queryList[0];
}
for (size_t i = 1; i < queryList.size(); i++)
{
conditions += U(" AND ") + queryList[i];
}
string finalCondition(conditions.begin(), conditions.end());
vector<Vehicle> dbResult = DbHelper::getInstance()->getVehicleList((char *)finalCondition.c_str());
string table = "";
auto path2 = message.relative_uri().path();
string reply;
for (int i = 0; i < dbResult.size(); i++)
{
Vehicle v = dbResult[i];
string tr = "";
tr += v.Registration + "#";
tr += to_string(v.Make) + "#";
tr += "" + v.Model + "#";
tr += "" + v.Owner + "#";
table += tr;
}
utility::string_t replyText(table.begin(), table.end());
message.reply(status_codes::OK, replyText).then([](pplx::task<void> t) { handle_error(t); });
}
示例10: operator
int operator() (const http_request& request, http_response* response)
{
char buf[256] = {0};
std::string resp_body;
std::vector<pid_t>::iterator it;
std::string path_str;
time_t time_now;
///只允许get方法
http_request::request_method method = request.get_method();
if (method != http_request::rGet)
goto err;
///只允许请求/
path_str =request.get_path();
if (path_str != "/")
return -1;
if (request.get_request_head("Connection") == std::string("close")) {
response->add_header("Connection", "close");
response->set_close_conn(true);
}
snprintf(buf, sizeof(buf), "uid: %d \r\n", process_info::uid());
resp_body = buf + process_info::username() + "\r\n" +
process_info::hostname() + "\r\n" + "\r\n";
for (it = m_pid_vec_.begin(); it != m_pid_vec_.end(); ++it) {
resp_body += process_info::get_proc_status(*it) + "\r\n";
snprintf(buf, sizeof(buf), "opend Files: %d \r\n\r\n", process_info::get_opened_files(*it));
resp_body += buf;
}
response->set_status_code(http_response::k200Ok);
response->set_status_str("OK");
response->add_header("Content-Type", "text/plain");
response->add_header("Server", "async_serv");
response->add_header("Connection", "keep-alive");
::time(&time_now);
::strftime(buf, sizeof(buf), "%a, %d %b %Y %H:%M:%S GMT", ::gmtime(&time_now));
response->add_header("Date", buf);
response->set_body(resp_body);
return 0;
err:
return default_404_response(request, response);
}
示例11: validator
void
RestRollupsUri::handle_post(http_request request)
{
std::cout << request.method() << " : " << request.absolute_uri().path() << std::endl;
int rc = 0;
std::string resultstr;
std::pair<bool, std::string> result {true, std::string()};
char json[1024];
// extract json from request
snprintf(json, sizeof(json), "%s", request.extract_string(true).get().c_str());
std::cout << "JSON:\n" << json << std::endl;
rapidjson::Document document;
if (document.Parse(json).HasParseError())
{
rc = 1;
resultstr += "document invalid";
}
rapidjson::SchemaValidator validator(*_schema);
if (!document.Accept(validator)) {
rc = 1;
resultstr += get_schema_validation_error(&validator);
}
rapidjson::Value::MemberIterator name = document.FindMember("name");
rapidjson::Value::MemberIterator nocsv = document.FindMember("nocsv");
rapidjson::Value::MemberIterator quantity = document.FindMember("quantity");
rapidjson::Value::MemberIterator maxdroop = document.FindMember("maxDroop");
rapidjson::Value::MemberIterator maxsdroop_validation = document.FindMember("maxDroopMaxtoMinIOPSSection");
// Execute Ivy Engine command
if (rc == 0)
{
std::unique_lock<std::mutex> u_lk(goStatementMutex);
std::pair<int, std::string>
rslt = m_s.create_rollup(name->value.GetString(),
(nocsv != document.MemberEnd() ? nocsv->value.GetBool() : false),
false /* have_quantity_validation */,
(maxsdroop_validation != document.MemberEnd() ? maxsdroop_validation->value.GetBool() : false),
(quantity != document.MemberEnd() ? quantity->value.GetInt() : 1),
(maxdroop != document.MemberEnd() ? maxdroop->value.GetDouble() : 6.95323e-310));
}
http_response response(status_codes::OK);
make_response(response, resultstr, result);
request.reply(response);
}
示例12: response
void
RestRollupsUri::handle_get(http_request request)
{
std::cout << request.method() << " : " << request.absolute_uri().path() << std::endl;
http_response response(status_codes::OK);
std::string resultstr("Not Supported");
std::pair<bool, std::string> result {true, std::string()};
resultstr = m_s.show_rollup_structure();
make_response(response, resultstr, result);
request.reply(response);
return;
}
示例13: handle_post
// Respond to HTTP::POST messages
// Post data will contain the postal code or location string.
// Aggregate location data from different services and reply to the POST request.
void CasaLens::handle_post(http_request message)
{
auto path = message.relative_uri().path();
if (0 == path.compare(U("/")))
{
message.extract_string()
.then([=](const utility::string_t& location) { get_data(message, location); })
.then([](pplx::task<void> t) { handle_error(t); });
}
else
{
message.reply(status_codes::NotFound, U("Path not found")).then([](pplx::task<void> t) { handle_error(t); });
}
}
示例14: handle_post
// Respond to HTTP::POST messages
// Post data will contain the postal code or location string.
// Aggregate location data from different services and reply to the POST request.
void CasaLens::handle_post(http_request message)
{
auto path = message.relative_uri().path();
if (0 == path.compare(U("/")))
{
message.extract_string().then([=](const utility::string_t& location)
{
get_data(message, location);
}).then(std::bind(&handle_error, std::placeholders::_1));
}
else
{
message.reply(status_codes::NotFound, U("Path not found")).then(std::bind(&handle_error, std::placeholders::_1));
}
}
示例15: 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());
}