c语言实现cgi之cgic库使用

版权声明:转载请关注我的公众号-青儿创客基地 https://blog.csdn.net/Zhu_Zhu_2009/article/details/89302797

参考

cgic官网

API

cgiFormString

获取字符串参数

cgiFormStringNoNewlines

去掉字符串的carriage,就是不换行

cgiFormStringSpaceNeeded

相对于cgiFormStringNoNewlines,可以控制获取字符串终端Space个数

cgiHtmlEscape

使字符串中的<, >, &被转换成&lt;, &gt;, &amp

cgic库使用

下载https://boutell.com/cgic/#obtain,解压,用vscode打开文件夹,打开PS,编译失败则删除15行rm -f libcgic.a,将cgitest.cgi拷贝到服务器,

PS C:\dog\program\cgi\cgic207> mingw32-make
rm -f libcgic.a
process_begin: CreateProcess(NULL, rm -f libcgic.a, ...) failed.
make (e=2): 系统找不到指定的文件。
mingw32-make: *** [Makefile:16: libcgic.a] Error 2
PS C:\dog\program\cgi\cgic207> mingw32-make
ar rc libcgic.a cgic.o
ranlib libcgic.a
gcc -g -Wall   -c -o cgictest.o cgictest.c
gcc cgictest.o -o cgictest.cgi -L./ -lcgic
gcc -g -Wall   -c -o capture.o capture.c
gcc capture.o -o capture -L./ -lcgic
PS C:\dog\program\cgi\cgic207> cp .\cgictest.cgi C:\Apache24\cgi-bin

浏览器打开http://localhost/cgi-bin/cgictest.cgi,显示,
在这里插入图片描述
动态生成的HTML为,

<HTML><HEAD>
<TITLE>cgic test</TITLE></HEAD>
<BODY><H1>cgic test</H1>
<!-- 2.0: multipart/form-data is required for file uploads. --><form method="POST" enctype="multipart/form-data" 	action="/cgi-bin/cgictest.cgi">
<p>
Text Field containing Plaintext
<p>
<input type="text" name="name">Your Name
<p>
Multiple-Line Text Field
<p>
<textarea NAME="address" ROWS=4 COLS=40>
Default contents go here. 
</textarea>
<p>
Checkbox
<p>
<input type="checkbox" name="hungry" checked>Hungry
<p>
Text Field containing a Numeric Value
<p>
<input type="text" name="temperature" value="98.6">
Blood Temperature (80.0-120.0)
<p>
Text Field containing an Integer Value
<p>
<input type="text" name="frogs" value="1">
Frogs Eaten
<p>
Single-SELECT
<br>
<select name="colors">
<option value="Red">Red
<option value="Green">Green
<option value="Blue">Blue
</select>
<br>
Multiple-SELECT
<br>
<select name="flavors" multiple>
<option value="pistachio">Pistachio
<option value="walnut">Walnut
<option value="creme">Creme
</select>
<p>Exclusive Radio Button Group: Age of Truck in Years
<input type="radio" name="age" value="1">1
<input type="radio" name="age" value="2">2
<input type="radio" name="age" value="3" checked>3
<input type="radio" name="age" value="4">4
<p>Nonexclusive Checkbox Group: Voting for Zero through Four Candidates
<input type="checkbox" name="vote" value="A">A
<input type="checkbox" name="vote" value="B">B
<input type="checkbox" name="vote" value="C">C
<input type="checkbox" name="vote" value="D">D
<p>File Upload:
<input type="file" name="file" value=""> (Select A Local File)
<p>
<p>Set a Cookie<p>
<input name="cname" value=""> Cookie Name
<input name="cvalue" value=""> Cookie Value<p>
<input type="submit" name="testcgic" value="Submit Request">
<input type="reset" value="Reset Request">
<p>Save the CGI Environment<p>
Pressing this button will submit the form, then save the CGI environment so that it can be replayed later by calling cgiReadEnvironment (in a debugger, for instance).<p>
<input type="submit" name="saveenvironment" value="Save Environment">
</form>
</BODY></HTML>

猜你喜欢

转载自blog.csdn.net/Zhu_Zhu_2009/article/details/89302797