C语言开发CGI程序的简单例子
2024-10-11 01:03:59
这年头用C语言开发cgi的已经不多,大多数的web程序都使用java、php、python等这些语言了。
但是本文将做一些简单的cgi实例。
首先配置环境
#这里是使用的apache AddHandler cgi-script .cgi
#下面的配置 一般在httpd.conf都已经配好了
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"
<Directory "/var/www/cgi-bin">
AllowOverride None
Options None
Order allow,deny
Allow from all
</Directory>
例子
//在目录 /var/www/cgi-bin 下 //添加test.c 文件 #include <stdio.h>
#include <stdlib.h>
#include <string.h> int main(){
char * out;
char * method; printf("Content-type: text/html\n\n");
printf("<h3>CGI test</h3><hr/>"); method = getenv("REQUEST_METHOD"); //get
if(!strcmp(method,"GET")){
out = getenv("QUERY_STRING");
printf("get reuslt:<br><br>");
printf("%s\n", out);
}
} //编译的时候把后缀改为.cgi
gcc test.c -o test.cgi
访问 http://localhost/cgi-bin/test.cgi?test=1&asd=1
看到如下结果
CGI test
get reuslt:
test=1&asd=1
最新文章
- Raft论文的一些问题
- 如何在nopcommerce3.3注册页面添加密码强度检查仪?
- Java for LeetCode 189 Rotate Array
- FTP服务器移动文件目录
- Dagger2学习资源
- sgu 107 987654321 problem
- PID38 串的记数(codevs2077)
- (2)入门指南——(3)为什么jquery工作的很好(Why jQuery works well)
- StaggeredGridView+universal-image-loader载入网路图片实现瀑布流
- html中返回上一页
- Effective前端6:避免页面卡顿
- etcd 增减节点
- LeetCode - Fruit Into Baskets
- vue项目,npm install后,npm run dev报错问题
- iOS证书(.p12)和描述文件(.mobileprovision)申请
- scheduling.quartz.CronTriggerBean has interface org.quartz.CronTrigger as super class
- # 20155209 2016-2017-2 《Java程序设计》第六周学习总结
- 开发npm模块经验总结
- PHP迭代器的小坑
- Memcached安装教程及使用