我正在使用boost 1.54.0.您可以在下面找到说明我的问题的最小示例.
我使用boost日志的severity_logger.我想从流中配置我的接收器.(在下面的示例中,我使用了一个字符串流.在我的实际应用程序中,流来自一个文件.)我想使用%Severity%来输出或过滤.
我的问题是:如果我在下面的例子中给出它,%Severity%为空.
%LineID%和%Message%按预期填充.如果我在outcommented行中设置了一个接收器,它会按预期工作.
有任何想法吗?
#include <boost/log/sources/severity_logger.hpp>
#include <boost/log/sources/record_ostream.hpp>
#include <boost/log/utility/setup/common_attributes.hpp>
#include <boost/log/utility/setup/from_stream.hpp>
#include <boost/log/utility/setup/console.hpp>
#include <boost/log/expressions.hpp>
enum SeverityLevel { trace, fatal };
int main (int argc, char *argv[])
{
boost::log::add_common_attributes();
/*
struct severity_tag;
boost::log::add_console_log(std::clog,
boost::log::keywords::format = (
boost::log::expressions::stream
<< boost::log::expressions::attr< unsigned int >("LineID")
<< ": <" << boost::log::expressions::attr<SeverityLevel, severity_tag >("Severity")
<< "> " << boost::log::expressions::smessage)
); */
std::stringstream s;
s << "[Sinks.MySink]" << std::endl;
s << "Destination=Console" << std::endl;
s << "Format=\"%LineID%: <%Severity%> - %Message%\"" …Run Code Online (Sandbox Code Playgroud) 我将使用C++库将数据发送到我们公司的REST-Web服务.我开始升压和野兽与给出的例子在这里代码:: Blocks的下一个Ubuntu的16.04环境.该文档没有帮助我解决以下问题:
我的代码或多或少等于示例,我可以成功编译并向我的测试Web服务发送GET请求.
但是如何在此定义中的请求(req)中设置数据:
:
beast::http::request<beast::http::string_body> req;
req.method("GET");
req.target("/");
:
Run Code Online (Sandbox Code Playgroud)
我尝试使用一些req.body.???,但代码completition没有给我一个功能的提示(顺便说一句.不工作).我知道req.method必须更改为"POST"才能发送数据.
Google没有显示有关此问题的新示例,仅以上述代码为例.
有人提示代码示例或使用关于野兽(咆哮)的人.或者我应该使用websockets?或者只有boost :: asio 在这里回答?
提前谢谢,原谅我糟糕的英语.
我从boost :: beast网站复制websocket示例并运行它的Websocket会话工作正常,但我不知道如何将收到的multi_buffer转换为字符串.
下面的代码是websocket会话处理程序.
void
do_session(tcp::socket &socket) {
try {
// Construct the stream by moving in the socket
websocket::stream <tcp::socket> ws{std::move(socket)};
// Accept the websocket handshake
ws.accept();
while (true) {
// This buffer will hold the incoming message
boost::beast::multi_buffer buffer;
// Read a message
boost::beast::error_code ec;
ws.read(buffer, ec);
if (ec == websocket::error::closed) {
break;
}
// Echo the message back
ws.text(ws.got_text());
ws.write(buffer);
}
cout << "Close" << endl;
}
catch (boost::system::system_error const &se) {
// This indicates that the …Run Code Online (Sandbox Code Playgroud)