gpt4 book ai didi

c - 编写自定义 http 服务器,支持 AJAX 是否需要通过 HTTP GET 进行额外代码?

转载 作者:可可西里 更新时间:2023-11-01 16:34:07 24 4
gpt4 key购买 nike

我必须用 C 编写一个可以在嵌入式系统处理器上运行的非常轻量级的服务器。

我计划只支持 GET 请求。大多数内容将是静态的,但它们将由 C CGI 文件生成(是的,我知道,这很痛苦。但我们只有 C 可供我们使用)。

我能支持 AJAX GET 请求吗?我不知道是否需要特殊的服务器端代码来处理它们。我觉得 AJAX 就是客户端。

最佳答案

您应该问自己的问题是,您为什么需要编写自定义 HTTP 服务器。研究现有的解决方案,看看它们是否满足您的需求。假设您有某种 POSIX 层可以在其上编程,您可以将几种轻量级 HTTP 服务器移植到您的嵌入式系统:

  • Libmicrohttpd :

    GNU libmicrohttpd is a small C library that is supposed to make it easy to run an HTTP server as part of another application. GNU GNU Libmicrohttpd is free software and part of the GNU project.

  • lightttpd :

    Security, speed, compliance, and flexibility -- all of these describe lighttpd (pron. lighty) which is rapidly redefining efficiency of a webserver; as it is designed and optimized for high performance environments. ... it's Open Source licensed under the revised BSD license.

  • nginx :

    nginx [engine x] is an HTTP and reverse proxy server, as well as a mail proxy server, written by Igor Sysoev. ... Here are some of the success stories: Netflix, Wordpress.com, FastMail.FM. ... The sources and documentation are distributed under the 2-clause BSD-like license.

  • thttpd :

    thttpd is a simple, small, fast, and secure HTTP server. It doesn't have a lot of special features, but it suffices for most uses of the web, it's about as fast as the best full-featured servers (Apache, NCSA Netscape), and it has one extremely useful feature (URL-traffic-based throttling) that no other server currently has.

之所以劝你不要自己实现,是因为 AJAX 在很大程度上依赖于 HTTP/1.1 的特性来提供高质量的用户体验,而从头开始实现所有 HTTP/1.1 是一项相当艰巨的任务,在服务器稳定且性能足以成为令人满意的产品之前,可能需要多次开发迭代。

关于c - 编写自定义 http 服务器,支持 AJAX 是否需要通过 HTTP GET 进行额外代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17636210/

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