用C语言和VC6.0做个最简单的CGI程序,并且运行在apache服务器环境中。

本文介绍一个最简单的CGI程序.

开发环境:vc++ 6.0

运行环境: apache2.2

创建者:seasun/csdn

开发步骤:

1,在VC6里面建立一个win32 console application项目,名字为"basic" 

2,在main函数中复制如下内容:

// basic.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
//create by seasun

int main(int argc, char* argv[])
{
 printf("Contenttype:text/html/n/n"); //根据HTTP协议,这里一定要有个空行。
 printf("<html>");  
 printf("<body>");  

 printf("Hello CGI!/n");
 printf("Run On Apache2.2/n");
 printf("Create In Visual C++ 6.0/n");

 printf("</body>");  
 printf("</html>");

 return 0;
}

 

3,编译一个release版本的,将生成的exe文件 "basic.exe"复制到 apache的cgi-bin目录中,也可以将exe后缀名去掉.

4,在浏览器地址栏输入http://localhost/cgi-bin/basic.exe (或不要后缀名)回车后,就可以看到输出的结果

注意:如果没有 printf("Contenttype:text/html/n/n"); 这句,在apache的log文件中会发现如下信息:

"malformed header from script. Bad header="

这是说CGI程序的输出不符合HTTP协议造成的.根据HTTP协议,这里一定要有个空行。. 本文完,seasun

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值