gpt4 book ai didi

c - C 中的简单 HTTP 服务器 - 如何响应浏览器?

转载 作者:太空狗 更新时间:2023-10-29 15:24:34 26 4
gpt4 key购买 nike

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

    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 未找到内容类型:文本/html

为什么没有加载内容?

最佳答案

HTTP 要求行以 CR+LF 结束,所以试试 \r\n

关于c - C 中的简单 HTTP 服务器 - 如何响应浏览器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15648965/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com