-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Server logging does not show body with a POST #367
Comments
@dkeeney, I looked into the post method in your server example in #366. svr.Post("/network", [&](const Request &req, Response &res, const ContentReader &content_reader) {
content_reader([&](const char *data, size_t data_length) {
res.body.append(data, data_length);
return true;
});
// here is where I would normally create the resource.
std::cout << "Creating resource /network with configuration: " << res.body << std::endl;
std::string token = "0001";
res.set_content(token+"\n", "text/plain");
});
svr.Post("/network", [&](const Request &req, Response &res) {
// here is where I would normally create the resource.
std::cout << "Creating resource /network with configuration: " << res.body << std::endl;
std::string token = "0001";
res.set_content(token+"\n", "text/plain");
}); Here is the result:
Is it what you expected? Please let me know if I misunderstood your situation. By the way, If we use the POST API with Content Receiver, cpp-httplib doesn't use svr.Post("/content_receiver",
[&](const Request &req, Response &res, const ContentReader &content_reader) {
if (req.is_multipart_form_data()) {
MultipartFormDataItems files;
content_reader(
[&](const MultipartFormData &file) {
files.push_back(file);
return true;
},
[&](const char *data, size_t data_length) {
files.back().content.append(data, data_length);
return true;
});
} else {
std::string body;
content_reader([&](const char *data, size_t data_length) {
body.append(data, data_length);
return true;
});
res.set_content(body, "text/plain");
}
}); Hope it helps. |
Yes!!! That was it. When I removed the ContentReader I now have the body in the logs. |
Refer to Issue #366 You can use this client/server pair to see this problem.
On the server side, the logging facility is passed a 'req' argument. For a POST message the req.body is always empty while printing the log even though a body was received and processed by the server.
I tried this with version 0.5.5 and with version 0.5.6
The text was updated successfully, but these errors were encountered: