简体   繁体   English

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

[英]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.

相关问题 我无法使用浏览器的简单代理服务器获得http响应 - I am unable to get a http response using simple proxy server to browser C:简单的 HTTP 服务器。 读取本地文件并从浏览器下载 - C: simple HTTP server. Read a local file and download it from browser 简单C执行HTTP POST并使用响应的示例 - Simple C example of doing an HTTP POST and consuming the response C套接字Web服务器未在浏览器中显示html,仅发送HTTP响应 - C socket Webserver not displaying html in browser, only sending HTTP response C中的简单http服务器,多进程无法正常工作 - Simple http server in C, multiple process not work properly 在 C 中使用套接字编程的简单 HTTP 服务器在 Chrome 上失败 - Simple HTTP server using socket programming in C failed on Chrome C 浏览器在网页上显示服务器套接字响应,但网页一直在加载 - C browser displays server socket response on webpage, but webpage keeps loading C-SERVER:HTTP响应缺少新行 - C-SERVER : HTTP response missing new line 我写了一个简单的 http 服务器,似乎可以工作,但是在尝试通过浏览器访问时遇到问题 - I wrote a simple http server that seems to work, but I run into issues when trying to access through browser 反汇编HTTP响应(C) - Disassemble HTTP Response (C)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM