Slight cleanup and added convenience function to retrieve Request::content string.
This commit is contained in:
parent
c58b7a788e
commit
7951ded3ec
3 changed files with 31 additions and 15 deletions
|
|
@ -24,10 +24,12 @@ int main() {
|
|||
//Add resources using path-regex and method-string, and an anonymous function
|
||||
//POST-example for the path /string, responds the posted string
|
||||
server.resource["^/string$"]["POST"]=[](HttpServer::Response& response, shared_ptr<HttpServer::Request> request) {
|
||||
//Retrieve string from istream (request->content)
|
||||
stringstream ss;
|
||||
ss << request->content.rdbuf();
|
||||
string content=ss.str();
|
||||
//Retrieve string:
|
||||
auto content=request->content.string();
|
||||
//request->content.string() is a convenience function for:
|
||||
//stringstream ss;
|
||||
//ss << request->content.rdbuf();
|
||||
//string content=ss.str();
|
||||
|
||||
response << "HTTP/1.1 200 OK\r\nContent-Length: " << content.length() << "\r\n\r\n" << content;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue