-
Notifications
You must be signed in to change notification settings - Fork 884
Open
Description
When I initiate a post request, if there are no parameters, I can return success. If there are JSON parameters, I will encounter error 204
My Code:
#include "crow.h"
#include "crow/middlewares/cors.h"
int main()
{
crow::App<crow::CORSHandler> app;
auto& cors = app.get_middleware<crow::CORSHandler>();
cors
.global()
.origin("*")
.headers("origin, x-requested-with, accept, access-control-allow-origin, authorization, content-type")
.methods("POST"_method, "GET"_method, "PUT"_method, "DELETE"_method, "PATCH"_method, "OPTIONS"_method)
.allow_credentials();
// 处理 POST 请求的路由
CROW_ROUTE(app, "/sayHello")
.methods(crow::HTTPMethod::Post)
([](const crow::request& req) {
// 构造响应
crow::json::wvalue response_json;
response_json["message"] = "接收到的名字:" + 11;
// 返回 JSON 数据
return crow::response(response_json);
});
// 启动服务器,监听端口 18080
app.port(18080).run();
}
Metadata
Metadata
Assignees
Labels
No labels