4

我的服务器正在向请求发送带有正文的示例响应标头:

    static char* not_found_response_template = 
      "HTTP/1.1 404 Not Found\n"
      "Content-type: text/html\n"
      "\n"
      "<html>\n"
      " <body>\n"
      "  <h1>Not Found</h1>\n"
      "  <p>The requested URL was not found on this server.</p>\n"
      " </body>\n"
      "</html>\n";


    len = strlen(not_found_response_template);
    send(newSct, not_found_response_template, len, 0);

它发送正确,但 Firefox 继续加载,直到我取消传输。

Firefox 插件 HttpRequestHelper 显示了这一点:

获取本地主机:6666

-- 响应 -- 404 Not Found Content-Type: text/html

为什么内容没有加载?

4

2 回答 2

5

HTTP 要求行由 CR+LF 终止,因此请尝试\r\n.

于 2013-03-26T23:04:11.353 回答
2

发送响应后尝试刷新和/或关闭套接字。

于 2013-03-26T23:04:13.763 回答