- 论坛徽章:
- 0
|
在网上找了个cgi的例子
下面两个文件的编码都是gb2312
测试get时:
传进去的中文参数回显时显示乱码英文正常,而在cpp中写入的“中文”两个字可以正常显示。
我的系统是linux
服务器Apache/2.2.9(Ubuntu)
请个各位帮忙看一下,第一次接触cgi编程。谢谢
test-cgi.cpp
- #include <algorithm>
- #include <fstream>
- #include <iomanip>
- #include <iostream>
- #include <iterator>
- #include <list>
- #include <map>
- #include <set>
- #include <sstream>
- #include <string>
- #include <queue>
- #include <vector>
- int main( void )
- {
- fprintf( stdout, "Content-type:text/html;charset=gb2312\n\n");
- fprintf( stdout, "<html><title>get</title>\n");
- if( getenv("QUERY_STRING" ) )
- {
- fprintf( stdout, getenv("QUERY_STRING" ) );
- fprintf(stdout, "中文");
- }
- else
- {
- fprintf( stdout, "(NULL)\n" );
- }
- fprintf( stdout, "</html>\n" );
- fflush(stdout);
- return 0;
- };
复制代码
testcgi.html
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
- <title>表单测试</title>
- </head>
- <body>
- <form method="get" name="test-get" action="./cgi-bin/test-get.cgi">
- <input name="name"><input name="pswd"><input type=submit value="get">
- </form>
- <br><br>
- <form method="post" name="test-post" action="./cgi-bin/test-post.cgi">
- <input name="name"><input name="pswd"><input type=submit value="post">
- </form>
- </body>
- </html>
复制代码 |
|