简体   繁体   English

HTTP / GET后几秒钟引发Poco :: Net :: NoMessageException

[英]Poco::Net::NoMessageException raised few seconds after HTTP/GET

Duplicate from POCO GitHub issue 与POCO GitHub问题重复

I'm building a simple web server using Poco with Visual Studio 2015 on Windows 10 . 我正在Windows 10上使用PocoVisual Studio 2015构建一个简单的Web服务器。

A Poco::Net::NoMessageException is raised few seconds (approx. 15 secs) after connecting to this server with a web browser. 使用Web浏览器连接到此服务器几秒钟(约15秒)后,就会引发Poco :: Net :: NoMessageException It will happen again after refreshing the page; 刷新页面后,它将再次发生; its doing this after each connection. 在每次连接后执行此操作。

I didn't find anything in documentation, forum, stackoverflow. 我没有在文档,论坛,stackoverflow中找到任何东西。 It would be very helpful to have a description in documentation of how/when/why these exceptions coming from deep inside the library are raised. 在文档中描述如何/何时/为什么从库内部产生这些异常将是非常有帮助的。

I also tried (just for fun) a std::cout << req.getURI() << std::endl; 我还尝试(只是为了好玩)一个std::cout << req.getURI() << std::endl; in handleRequest(...) and got a Memory Access Violation at address 0x00000000 with no other code in function. handleRequest(...)在地址0x00000000处遇到了内存访问冲突,而函数中没有其他代码。

Here is my code. 这是我的代码。 Preprocessor statements are omitted. 省略预处理程序语句。

MyApp.c MyApp.c

int main(int argc, char ** argv)
{
    myHTTPServer server;
    return server.run(argc, argv);
}

myHTTPRequestHandlerFactory myHTTPRequestHandlerFactory

// Header
class myHTTPRequestHandlerFactory : public HTTPRequestHandlerFactory
{
    public:
        virtual HTTPRequestHandler* createRequestHandler(const HTTPServerRequest&);
};

// Code
HTTPRequestHandler* myHTTPRequestHandlerFactory::createRequestHandler(const HTTPServerRequest& handler) {
    return new myHTTPRequestHandler;
}

myHTTPRequestHandler myHTTPRequestHandler

// Header
class myHTTPRequestHandler : public HTTPRequestHandler
{
    public:
        virtual void handleRequest(HTTPServerRequest &, HTTPServerResponse &);
};

// Code
void myHTTPRequestHandler::handleRequest(HTTPServerRequest & request, HTTPServerResponse & response) {
    response.setStatus(HTTPResponse::HTTP_OK);
    //response.setContentLength(1024);
    //response.setChunkedTransferEncoding(true);
    std::ostream& out = response.send();
    out << "<html><head></head><body>POCO POCO POCO</body></html>";
    out.flush();
}

myHTTPServer myHTTPServer

// Header
class myHTTPServer : public ServerApplication
{
    protected:
        int main(const std::vector<std::string>& v) {
            HTTPServer server(new myHTTPRequestHandlerFactory, ServerSocket(80), new HTTPServerParams);

            server.start();

            std::cout << "Server started" << std::endl;

            waitForTerminationRequest();

            std::cout << "Server stopped" << std::endl;

            server.stop();

            return Application::EXIT_OK;
        }
};

// No code in .c file

Thanks for helping me out 谢谢你的协助

According to this answer , it's a normal POCO behaviour to raise Poco::Net::NoMessageException exceptions for no exceptional reason and you should safely ignore them. 根据此答案 ,无特殊原因而引发Poco :: Net :: NoMessageException异常是正常的POCO行为,您应该safely ignore它们。

For the Memory Access Violation , it's normal as it's not allowed to call std::cout in HTTPRequestHandler::handleRequest(...) . 对于内存访问冲突 ,这是正常现象,因为不允许在HTTPRequestHandler::handleRequest(...)调用std::cout

I'm facing the same problem, right after changing the way I handle URLs routings. 在更改我处理URL路由的方式之后,我正面临着同样的问题。

I think it may be due to the second request send automagically by Chrome : The favicon. 我认为这可能是由于Chrome自动发送的第二个请求:收藏夹图标。 Right after receiving HTML content, the browser interrogates the server again to get the fancy tab icon, if any. 在收到HTML内容后,浏览器立即再次询问服务器以获取精美的标签图标(如果有)。 Make sure you handle such requests gracefully, with a 404 error if needed. 确保妥善处理此类请求,如果需要,则显示404错误。

As a general advice, redirect all unknown requests to a handler that sends the relevant HTTP error code, to ensure you reply to all requests. 作为一般建议,将所有未知请求重定向到发送相关HTTP错误代码的处理程序,以确保您答复所有请求。

You can also log all incoming requests (at least in debug, if you don't want to log sensitive info) and check the Developper Tools section of your browser to check which requests are sent. 您还可以记录所有传入的请求(如果不想记录敏感信息,则至少要在调试中进行记录),并检查浏览器的“开发人员工具”部分以检查发送了哪些请求。 If you are not calling a URL beginning with https:// on a http server (in which case additionnal exchanges may take place), your browser should not send any other request without logging it in the network tab. 如果您未在http服务器上调用以https://开头的URL(在这种情况下可能进行附加交换),则浏览器在未将其记录在“网络”标签中的情况下不应发送任何其他请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM