Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如果我访问该页面,带有卡萨布兰卡的http服务器将崩溃_C++_Httpserver_Casablanca - Fatal编程技术网

C++ 如果我访问该页面,带有卡萨布兰卡的http服务器将崩溃

C++ 如果我访问该页面,带有卡萨布兰卡的http服务器将崩溃,c++,httpserver,casablanca,C++,Httpserver,Casablanca,我使用来自卡萨布兰卡或cpprest库的http_侦听器创建了一个简单的应用程序: #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)

我使用来自卡萨布兰卡或cpprest库的http_侦听器创建了一个简单的应用程序:

#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;
}

我不明白的是,当我试图访问页面X.X.X.X:XXXX;不管是哪一个,我已经测试了很多次,应用程序毫无例外地崩溃了,我没有收到任何数据,无法加载网页,因为服务器没有发送任何数据。错误代码:ERR\u EMPTY\u响应页。

嗯,您在回复中没有发送任何数据,只是发送状态代码。所以,是的,如果您的客户需要数据,而您却需要数据,那么这种情况就会发生


作为message参数传递的http_请求类肯定希望在调用reply方法或reply之前首先设置内容,并将reply数据作为另一个参数,并且该参数的默认数据为空。无论如何,您必须以某种方式提供内容数据,而您的客户正期待着它,并且依赖于程序员您来满足它。

问题似乎出在CPPREST的版本上。我已经更新到2.5版本,并且它工作正常…

我仍然认为cpprest存在问题。。。你能发布一些小代码吗,它应该是什么样子的我说,因为这是非常相似的,在他们的网站上,我尝试过,并有相同的问题。。。