Skip to content
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

cors error #423

Open
woxiaobaimao opened this issue Dec 8, 2023 · 0 comments
Open

cors error #423

woxiaobaimao opened this issue Dec 8, 2023 · 0 comments

Comments

@woxiaobaimao
Copy link

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();

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant