http服务器与卡萨布兰卡崩溃,如果我访问的页面 [英] http server with casablanca crashes if I access the page

查看:448
本文介绍了http服务器与卡萨布兰卡崩溃,如果我访问的页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从casablanca(或cpprest)库中使用http_listener创建了一个简单的应用程序:

I have created a simple application with http_listener from casablanca (or cpprest) library:

#include <cpprest/http_listener.h>
#include <functional>

using namespace web::http::experimental::listener;
using namespace web::http;
using namespace web;

void handle_get(http_request message)
{
    message.reply(status_codes::OK, U("Hello, World!"));
};

void handle_post(http_request message)
{
    message.reply(status_codes::NotFound);
};

void handle_put(http_request message)
{
    message.reply(status_codes::NotFound);
};

void handle_delete(http_request message)
{
    message.reply(status_codes::NotFound);
};

#define TRACE(msg)            std::wcout << msg
#define TRACE_ACTION(a, k, v) std::wcout << a << L" (" << k << L", " << v << L")\n"

int main(int argc, char ** argv)
{
  uri_builder uri(U("http://127.0.0.1:61561"));
  http_listener listener(uri.to_uri());

  listener.support(methods::GET, handle_get);
  listener.support(methods::POST, handle_post);
  listener.support(methods::PUT, handle_put);
  listener.support(methods::DEL, handle_delete);

  try
  {
     listener
        .open()
        .then([&listener](){TRACE(L"\nstarting to listen\n");})
       .wait();

      while (true);
  }
  catch (std::exception const & e)
  {
     std::wcout << e.what() << std::endl;
  }
  catch (...)
  {
     std::wcout << "Unknown exception" << std::endl;
  }

  return 0;
}

我不知道的是,当我尝试访问页面XXXX:XXXX;无论哪一个,我已经测试过很多),应用程序崩溃,没有例外,我得到没有收到数据,无法加载网页,因为服务器没有发送数据错误代码:ERR_EMPTY_RESPONSE 页。

What I do not get it is that when I try to access the page (X.X.X.X:XXXX; it does not matter which one, I have tested on many), the application is crashing with no exception and I get a "No data received, Unable to load the webpage because the server sent no data. Error code: ERR_EMPTY_RESPONSE" page.

推荐答案

似乎问题是CPPREST的版本。我已更新到2.5,它工作...

It seems that the problem was the version of CPPREST. I have updated to 2.5 and it worked...

这篇关于http服务器与卡萨布兰卡崩溃,如果我访问的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆