- 論壇徽章:
- 0
|
在網(wǎng)上找了個cgi的例子
下面兩個文件的編碼都是gb2312
測試get時:
傳進(jìn)去的中文參數(shù)回顯時顯示亂碼英文正常,而在cpp中寫入的“中文”兩個字可以正常顯示。
我的系統(tǒng)是linux
服務(wù)器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;
- };
復(fù)制代碼
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>
復(fù)制代碼 |
|