1

如何在 c++ crow中获取非 int 资源 ID 。我无法添加路由 CROW_ROUTE(app, "/uid/<std::string>")CROW_ROUTE(app, "/uid/<char*>")无法编译。示例中没有这种情况。我试过了

int main() {
    crow::SimpleApp app;
    CROW_ROUTE(app, "/uid/*").methods("GET"_method)
    ([](const crow::request& req){
        return "hello";
        });

    CROW_ROUTE(app, "/uid/<int>").methods("GET"_method)
    ([](const crow::request& req, int id){
        return std::to_string(id);
        });
    app.port(8888).run();
}

但他们都没有(虽然正确)拦截GET /uid/uid_123 HTTP/1.1(资源是一个字符串"uid_123"

对于下面的 python 代码,我想在 c++ crow 库中实现它

from flask import Flask
app = Flask(__name__)
@app.route("/uid/<path:path>")
def hello1(path):
    print ("it is path is ", path)
    return "user id is -" + path

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8888)

以上有什么解决方法吗?

4

1 回答 1

1

最初由github上的erowjihoo回答

CROW_ROUTE(app,"/uid/<path>")
    ([](std::string path){
     return path;
     });

除了intpath以下也可以工作:uintdoublestring

于 2018-05-17T09:59:02.887 回答