如何在C中创建AJAX服务器端脚本?

时间:2022-02-19 15:25:59

I am looking into AJAX for the first time and I would like to know if it's possible to make the requests from a server side CGI application written in C?

我是第一次看AJAX,我想知道是否有可能从用C编写的服务器端CGI应用程序发出请求?

Will the C application just use printf for the data, similar to this .asp example?

C应用程序是否只使用printf作为数据,类似于.asp示例?

4 个解决方案

#1


If I were you, I would stay away from C for server-side stuff. There are so many other languages that are better suited for this, but if you insist, you could use a library like cgic. Basically, you would just use the CGI handler from a server like Apache, but please, PLEASE use something other than C. It's very dangerous in the wrong hands, especially via CGI.

如果我是你,我会远离C服务器端的东西。有很多其他语言更适合这种情况,但如果你坚持,你可以使用像cgic这样的库。基本上,你只需要使用像Apache这样的服务器上的CGI处理程序,但是请,请使用C以外的其他东西。这在错误的手中非常危险,特别是通过CGI。

Use something like PHP or Perl to keep yourself sane. PHP is perfect for someone just starting out, and you won't have to futz around with compilation and making your CGI handler work/be secure.

使用像PHP或Perl这样的东西来保持自己的理智。 PHP对于刚开始的人来说是完美的,你不必为了编译而使你的CGI处理程序工作/安全。

#2


ASP does some magic, such as outputting the appropriate response headers, but other than that it really is that simple. The server-side of AJAX is just responding to requests. Output the right data in the expected format and you're done. Stick with REST principles and this becomes easy.

ASP做了一些魔术,例如输出适当的响应头,但除此之外,它确实很简单。 AJAX的服务器端只是响应请求。以预期的格式输出正确的数据,您就完成了。坚持REST原则,这变得容易。

#3


You can do scripting using C.

你可以用C做脚本。

Take a look at http://bellard.org/tcc/ - this is a small C99 compiler for Windows and UNIX. It has a unique feature: "-run" option. With this option, tinycc compiles the code into memory and executes it without creating an intermediate binary. Thus all you need to do is to create your CGI files like this:

看一下http://bellard.org/tcc/ - 这是一个适用于Windows和UNIX的小型C99编译器。它有一个独特的功能:“ - 运行”选项。使用此选项,tinycc将代码编译到内存中并执行它而无需创建中间二进制文件。因此,您需要做的就是创建这样的CGI文件:


#!path-to-tinycc-executable -run

// your C code goes below

//你的C代码如下

....

However, I have to agree with previous commenters that C is not great for server side CGI.

但是,我不得不同意以前的评论者,C对服务器端CGI来说不是很好。

#4


I am looking into AJAX for the first time and I would like to know if it's possible to make the requests from a server side CGI application written in C?

我是第一次看AJAX,我想知道是否有可能从用C编写的服务器端CGI应用程序发出请求?

I'll hop on the bandwagon, and say that it's usually easier to just use another language. However, I also understand that sometimes you have to use C - i.e., for embedded servers with limited resources. If that's the strongly suggest you use cgic, or heck, maybe even a framework like klone. I'm a bit biased towards the latter, though. It provides a nice interface to getting request objects, almost like the scripting variety of frameworks.

我会跳上这个潮流,并说通常使用另一种语言会更容易。但是,我也理解有时您必须使用C - 即,对于资源有限的嵌入式服务器。如果那是强烈建议你使用cgic,或者heck,甚至可能是像klone这样的框架。不过,我对后者有些偏见。它为获取请求对象提供了一个很好的界面,几乎就像脚本编写各种框架一样。

#1


If I were you, I would stay away from C for server-side stuff. There are so many other languages that are better suited for this, but if you insist, you could use a library like cgic. Basically, you would just use the CGI handler from a server like Apache, but please, PLEASE use something other than C. It's very dangerous in the wrong hands, especially via CGI.

如果我是你,我会远离C服务器端的东西。有很多其他语言更适合这种情况,但如果你坚持,你可以使用像cgic这样的库。基本上,你只需要使用像Apache这样的服务器上的CGI处理程序,但是请,请使用C以外的其他东西。这在错误的手中非常危险,特别是通过CGI。

Use something like PHP or Perl to keep yourself sane. PHP is perfect for someone just starting out, and you won't have to futz around with compilation and making your CGI handler work/be secure.

使用像PHP或Perl这样的东西来保持自己的理智。 PHP对于刚开始的人来说是完美的,你不必为了编译而使你的CGI处理程序工作/安全。

#2


ASP does some magic, such as outputting the appropriate response headers, but other than that it really is that simple. The server-side of AJAX is just responding to requests. Output the right data in the expected format and you're done. Stick with REST principles and this becomes easy.

ASP做了一些魔术,例如输出适当的响应头,但除此之外,它确实很简单。 AJAX的服务器端只是响应请求。以预期的格式输出正确的数据,您就完成了。坚持REST原则,这变得容易。

#3


You can do scripting using C.

你可以用C做脚本。

Take a look at http://bellard.org/tcc/ - this is a small C99 compiler for Windows and UNIX. It has a unique feature: "-run" option. With this option, tinycc compiles the code into memory and executes it without creating an intermediate binary. Thus all you need to do is to create your CGI files like this:

看一下http://bellard.org/tcc/ - 这是一个适用于Windows和UNIX的小型C99编译器。它有一个独特的功能:“ - 运行”选项。使用此选项,tinycc将代码编译到内存中并执行它而无需创建中间二进制文件。因此,您需要做的就是创建这样的CGI文件:


#!path-to-tinycc-executable -run

// your C code goes below

//你的C代码如下

....

However, I have to agree with previous commenters that C is not great for server side CGI.

但是,我不得不同意以前的评论者,C对服务器端CGI来说不是很好。

#4


I am looking into AJAX for the first time and I would like to know if it's possible to make the requests from a server side CGI application written in C?

我是第一次看AJAX,我想知道是否有可能从用C编写的服务器端CGI应用程序发出请求?

I'll hop on the bandwagon, and say that it's usually easier to just use another language. However, I also understand that sometimes you have to use C - i.e., for embedded servers with limited resources. If that's the strongly suggest you use cgic, or heck, maybe even a framework like klone. I'm a bit biased towards the latter, though. It provides a nice interface to getting request objects, almost like the scripting variety of frameworks.

我会跳上这个潮流,并说通常使用另一种语言会更容易。但是,我也理解有时您必须使用C - 即,对于资源有限的嵌入式服务器。如果那是强烈建议你使用cgic,或者heck,甚至可能是像klone这样的框架。不过,我对后者有些偏见。它为获取请求对象提供了一个很好的界面,几乎就像脚本编写各种框架一样。