CGIC学习笔记



/**********************************CGIC********************/
#include "cgic.h"


extern char *cgiQueryString;


int cgiMain() {
char One[20];
char Two[20];
char Three[20];
cgiWriteEnvironment("/CHANGE/THIS/PATH/capcgi.dat");
cgiHeaderContentType("text/html");
fprintf(cgiOut, "<title>Captured</title>\n");
fprintf(cgiOut, "<h1>ok Captured</h1>\n");
fprintf(cgiOut, "Your form submission was captured for use in\n");
fprintf(cgiOut, "debugging CGI code.\n");
fprintf(cgiOut, "<H1>%s</H1>",cgiQueryString);
cgiFormString("one",One, 20);
cgiFormString("two",Two, 20);
cgiFormString("three",Three, 20);
fprintf(cgiOut, "<H5>%s</H5>",One);
fprintf(cgiOut, "<H3>%s</H3>",Two);
fprintf(cgiOut, "<H1>%s</H1>",Three);
return 0;
}


/*******************************************************/




/**********************************HTML********************/


<html>
<head>
<title>Test</title>
</head>
<body>
<form action="cgi-bin/testforcgic.cgi" method="get">
<input type="text" name="one">
<input type="text" name="two">
<input type="text" name="three">
<input type="submit" value="Continue &rarr;">
</form>
</body>
</html>


/*******************************************************/
1、头文件必须包含 cgic.h;
2、函数入口为cgiMain();
3、变量:char *cgiQueryString;作用:获取html所有输入的内容,(输入111,222,333)如果打印,现实为:one=111&two=222&three=333,注意,空格已被&取代,如果有


:或者其他符号都会被转换的;为了防止被转义,可使用反转义函数函数:cgiUnescapeChars(&buffer, cgiQueryString, strlen(cgiQueryString));注意,buffer内存是


被反转义函数分配的,所以在使用完毕记得释放:free(buffer)
4、cgiFormString("two",Two, 20);作用:获取输入参数的值。相关函数还有:cgiFormStringNoNewlines用来去掉换行符(如果用户是在一个TextArea里输入字符的话);

cgiFormStringSpaceNeeded用于测试输入值的长度,可以以此为依据,然后按需精确分配缓冲区。



参考资料;http://blog.youkuaiyun.com/ly61baby/article/details/6458335




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值