本文整理汇总了C++中HttpResponse::getResult方法的典型用法代码示例。如果您正苦于以下问题:C++ HttpResponse::getResult方法的具体用法?C++ HttpResponse::getResult怎么用?C++ HttpResponse::getResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpResponse
的用法示例。
在下文中一共展示了HttpResponse::getResult方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char **argv)
{
std::string body = "<html>hello world </html>";
auto service = std::make_shared<WrapTcpService>();
service->startWorkThread(2);
auto listenThread = ListenThread::Create();
listenThread->startListen(false, "0.0.0.0", 8080, [service, body](sock fd) {
service->addSession(fd, [body](const TCPSession::PTR& session) {
HttpService::setup(session, [body](const HttpSession::PTR& httpSession) {
httpSession->setHttpCallback([body](const HTTPParser& httpParser, const HttpSession::PTR& session) {
HttpResponse response;
response.setBody(body);
std::string result = response.getResult();
session->send(result.c_str(), result.size(), std::make_shared<std::function<void(void)>>([session]() {
session->postShutdown();
}));
});
httpSession->setWSCallback([](const HttpSession::PTR& httpSession, WebSocketFormat::WebSocketFrameType opcode, const std::string& payload) {
// ping pong
auto frame = std::make_shared<std::string>();
WebSocketFormat::wsFrameBuild(payload.c_str(), payload.size(), *frame, WebSocketFormat::WebSocketFrameType::TEXT_FRAME, true, true);
httpSession->send(frame);
});
});
}, false, nullptr, 1024 * 1024, false);
});
std::cin.get();
sock fd = brynet::net::base::Connect(false, "192.168.12.128", 8080);
if (fd != SOCKET_ERROR)
{
service->addSession(fd, [](const TCPSession::PTR& session) {
HttpService::setup(session, [](const HttpSession::PTR& httpSession) {
HttpRequest request;
HttpQueryParameter parameter;
parameter.add("value", "123456");
if (false)
{
request.addHeadValue("Accept", "*/*");
request.setMethod(HttpRequest::HTTP_METHOD::HTTP_METHOD_PUT);
request.setUrl("/v2/keys/asea/aagee");
request.setContentType("application/x-www-form-urlencoded");
request.setBody(parameter.getResult());
}
else
{
request.setMethod(HttpRequest::HTTP_METHOD::HTTP_METHOD_GET);
request.setUrl("/v2/keys/asea/aagee");
request.setQuery(parameter.getResult());
}
std::string requestStr = request.getResult();
httpSession->send(requestStr.c_str(), requestStr.size());
httpSession->setHttpCallback([](const HTTPParser& httpParser, const HttpSession::PTR& session) {
//http response handle
std::cout << httpParser.getBody() << std::endl;
});
});
}, false, nullptr, 1024 * 1024, false);
}
std::cin.get();
return 0;
}