【问题标题】:C++ Boost 1.66 using Beast http request Parser for parsing an stringC++ Boost 1.66 使用 Beast http request Parser 来解析字符串
【发布时间】:2018-04-10 14:51:06
【问题描述】:

我没有在我的项目中使用 beast http 服务器,但我正在寻找一种解决方案来在我的程序中解析 std::string 形式的 http 请求,是否可以使用 boost/beast/http/parser。 hpp 在这种情况下,如果是这样的话,如果你在代码中给出一个例子,那就太好了。 非常感谢

【问题讨论】:

    标签: c++ c++11 boost httprequest boost-beast


    【解决方案1】:

    是的,有可能:

    std::string s =
        "POST /cgi/message.php HTTP/1.1\r\n"
        "Content-Length: 5\r\n"
        "\r\n"
        "abcde";
    error_code ec;
    request_parser<string_body> p;
    p.put(boost::asio::buffer(s), ec);
    

    【讨论】:

    • bad method 在您的示例中写入error_code。 (提升 1.68)
    • 哎呀,对不起!该字符串包含 HTTP 响应而不是请求。我已经更新了代码示例。
    猜你喜欢
    • 2018-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-04
    相关资源
    最近更新 更多