枫 [长风破浪会有时,直挂云帆济沧海]jinjing.blog.chinaunix.net
一鸿秋水
全部博文(65)
2010年(13)
2009年(52)
迟迟吃a1
shadoubu
huang_gu
超级飞侠
格伯纳
cynthia
pei_0318
laoyouji
kofera_d
分类: 系统运维
2009-05-13 23:04:11
#include <stdio.h>#include <stdlib.h>int main(void){ char *data; char a[10],b[10]; printf("Content-Type:text/html\n\n"); printf("\n"); printf("\nGet Method\n\n"); printf("\n"); printf("\n"); data = getenv("QUERY_STRING"); if(sscanf(data,"a=%[^&]&b=%s",a,b)!=2){ printf("Error parameters should be entered!\n"); } else{ printf("a + b = %d\n",atoi(a)+atoi(b)); } printf(""); printf(""); printf("\n"); printf(" \n"); printf("\n"); return 0;}
#include <stdio.h>#include <stdlib.h>int main(void){ int len; char *lenstr,poststr[20]; char m[10],n[10]; printf("Content-Type:text/html\n\n"); printf("\n"); printf("\npost Method\n\n"); printf("\n"); printf("\n"); lenstr=getenv("CONTENT_LENGTH"); if(lenstr == NULL) printf("Error parameters should be entered!\n"); else{ len=atoi(lenstr); fgets(poststr,len+1,stdin); if(sscanf(poststr,"m=%[^&]&n=%s",m,n)!=2){ printf("Error: Parameters are not right!\n"); } else{ printf("m * n = %d\n",atoi(m)*atoi(n)); } } printf(""); printf(""); printf("\n"); printf("\n"); printf("\n"); fflush(stdout); return 0;}
<html><head><title>CGI Testing</title></head><body><table width="200" height="180" border="0" style="font-size:12px"><tr><td><div style="font-weight:bold; font-size:15px">Method: GET</div><div>please input two number:<div><form method="get" action="./cgi-bin/get"><input type="txt" size="3" name="a">+<input type="txt" size="3" name="b">=<input type="submit" value="sum"></form></td></tr><tr><td><div style="font-weight:bold; font-size:15px">Method: POST</div><div>please input two number:<div><form method="post" action="./cgi-bin/post"><input type="txt" size="3" name="m">*<input type="txt" size="3" name="n">=<input type="submit" value="resu"></form></td></tr><tr><td><inputtype="button" value="Back Home"onclick='javascript:window.location="./index.html"'></td></tr></table></body></html>
上一篇:goahead web server 特性及技术
下一篇:CGI环境变量
登录 注册