[英]Simple HTTP Server in C - How to response to Browser?
my server is sending a sample response header with body to a request: 我的服务器正在向请求发送带有正文的示例响应标头:
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);
it is sending it correctly but firefox keeps on loading until I cancel the transfer. 它正确发送它,但firefox继续加载,直到我取消传输。
the firefox plugin HttpRequestHelper shows this: firefox插件HttpRequestHelper显示了这个:
GET localhost:6666 获取localhost:6666
-- response -- 404 Not Found Content-Type: text/html - 响应 - 404未找到内容类型:text / html
why the content is not loaded? 为什么内容没有加载?
HTTP要求CR + LF终止行,所以请尝试\\r\\n
。
发送响应后尝试刷新和/或关闭套接字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.