与此类似(但更具体)的问题关于 cpp-netlib HTTP 服务器端中的标头的未回答问题的问题。
这是cpp-netlib 0.11.1
在 Linux/Debian/Sid/x86-64 上使用clang++
3.5 或g++
4.9-std=c++11
模式。
顺便说一句,我还问了一些关于cpp-netlib googlegroup 的例子......
#include <fstream>
#include <iostream>
#include <boost/network/protocol/http/server.hpp>
#define DEBUG_OUT(Out) do {std::cout << __FILE__ << ":" << __LINE__ \
<< ' ' << Out << std::endl;} while(0)
namespace netlib_http = boost::network::http;
struct Yaca_web;
typedef netlib_http::server<Yaca_web> Yaca_server;
struct Yaca_web {
void operator() (Yaca_server::request const& request,
Yaca_server::response &response)
{
DEBUG_OUT("web request source="
<< std::string(source(request))
//<< " uri=" << std::string(uri(request)) ///@@@@@
);
};
void log(const std::string&s) { DEBUG_OUT("log s=" << s); };
}; // end Yaca_web
void ya_web_service(int port) {
DEBUG_OUT("ya_web_service start port=" << port);
Yaca_web webhandler;
Yaca_server::options weboptions {webhandler};
weboptions.address("localhost");
weboptions.port(std::to_string(port));
weboptions.reuse_address(true);
Yaca_server webserver {weboptions};
DEBUG_OUT("ya_web_service before running server");
webserver.run();
DEBUG_OUT("ya_web_service end port=" << port);
}
如果我取消注释该行,则上面的代码不会编译,///@@@@@
但我将uri(request)
其用作盲目猜测:
In file included from ywebx.cc:4:
In file included from /usr/include/boost/network/protocol/http/server.hpp:13:
In file included from /usr/include/boost/network/protocol/http/request.hpp:18:
/usr/include/boost/network/protocol/http/message/wrappers/uri.hpp:25:44: error:
no member named 'uri' in
'boost::network::http::basic_request<tags::http_server>'
operator string_type() { return message_.uri().raw(); }
~~~~~~~~ ^
ywebx.cc:18:34: note: in instantiation of member function
'boost::network::http::impl::uri_wrapper<boost::network::http::tags::http_server>::operator
basic_string' requested here
<< " uri=" << std::string(uri(request))
^
./yacax.h:49:18: note: expanded from macro 'DEBUG_OUT'
<< ' ' << Out << std::endl;} while(0)
^
有谁知道如何获取更多信息:特别是方法、路径或 URI,以及HTTPPOST
具有常见application/x-www-form-urlencoded
MIME 类型请求,网络表单参数的字典(如果可能)?
我找不到cpp-netlib
Web 表单的 HTTP 服务的简单示例(在libonioncpp-netlib
的 C++11 中examples/post/
类似)