ÓÃC/C£«£«Ð´CGI³ÌÐò
ÓÃC/C£«£«Ð´CGI³ÌÐò
ʹÓÃCGIC¿âµÄ¼òÒª£º
¿âµÄº¯Êý˵Ã÷£º http://www.boutell.com/cgic/#cgiFormStringNoNewlines
1. ´òÓ¡CGI±ê×¼Êä³öÍ·²¿£º
cgiHeaderContentType£¨"text/plain"£©£»
»òÕߣº
fprintf£¨ stdout£¬ "Content-type£ºtext/plain\n\n"£©£»ºìÉ«²¿·Ö²»ÄÜд³ö“Contenttype”£¬·ñÔòä¯ÀÀÆ÷ÏÔʾÍøÒ³»á²»Õý³£¡£
2. ´¦ÀíRequest Method£º
//deal with "GET"/"POST" method
if (strncmp(cgiRequestMethod, "post",4) == 0)
{
handlePostRequest();
}
else //"GET"
{
handleGetRequest();
}
3. »ñÈ¡QueryStringÖеĸ÷¸ö×Ö¶ÎÖµ£º
cgiFormStringNoNewlines("query1", cmdstr, sizeof(cmdstr));
if (strcmp(cmdStr, "ip_address") == 0)
{
...
}
else
...
4. CGIÊä³ö£ºfprintf£¨cgiOut£¬ "%s\n"£¬ cgi_Output£©£»
ÒÔÏÂÊÇһЩϸ½Ú£º
Ò»¡¢ C/C++±àдCGI³ÌÐòÖ®form´¦Àí
1. GET
2. POST
3. ½áÊø
ÎÒÃÇÓÐÒ»ÕÅweb
test.html
<html>
<head>
<title>form test</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/t
Ïà¹ØÎĵµ£º
±¾ÎÄ´Ó½éÉÜ»ù´¡¸ÅÄîÈëÊÖ£¬Ì½ÌÖÁËÔÚC/C++ÖжÔÈÕÆÚºÍʱ¼ä²Ù×÷ËùÓõ½µÄÊý¾Ý½á¹¹ºÍº¯Êý£¬²¢¶Ô¼Æʱ¡¢Ê±¼äµÄ»ñÈ¡¡¢Ê±¼äµÄ¼ÆËãºÍÏÔʾ¸ñʽµÈ·½Ãæ½øÐÐÁ˲ûÊö¡£±¾ÎÄ»¹Í¨¹ý´óÁ¿µÄʵÀýÏòÄãչʾÁËtime.hÍ·ÎļþÖÐÉùÃ÷µÄ¸÷ÖÖº¯ÊýºÍÊý¾Ý½á¹¹µÄÏêϸʹÓ÷½·¨¡£
¹Ø¼ü×Ö£ºUTC£¨ÊÀ½ç±ê׼ʱ¼ä£©£¬Calendar Time£¨ÈÕÀúʱ¼ä£©£¬epoch£¨Ê±¼äµã ......
תע:
½ñÌìÓÐÍøÓÑÎʵ½Õâ¸öÎÊÌâ,ÓÚÊÇÔÚÍøÉÏËÑË÷ÁËÒ»ÏÂ,תÌùÕâ´Ë.
ÏàËƵÄÌ«¶àÁË,³ö´¦²»Ïê.Ôڴ˸ÐлÔ×÷Õß¾«²Ê½²½â.
Ò»¡¢Ô¤±¸ÖªÊ¶—³ÌÐòµÄÄÚ´æ·ÖÅä
Ò»¸öÓÉc/C++±àÒëµÄ³ÌÐòÕ¼ÓõÄÄÚ´æ·ÖΪÒÔϼ¸¸ö²¿·Ö
1¡¢Õ»Çø£¨stack£©— ÓɱàÒëÆ÷×Ô¶¯·ÖÅäÊÍ·Å £¬´æ·Åº¯ÊýµÄ²ÎÊýÖµ£¬¾Ö²¿±äÁ¿µÄÖµµÈ¡£Æä²Ù×÷·½Ê½Àà ......
PS:
½ñÌìÈ¥¸£ê¿²Î¼ÓËûÃǹ«Ë¾µÄ±ÊÊÔÁË£¬¿¼µÄ²»ÊǺÜˬ¡£¡£¡£¡£¡£Ò»Ð©ºÜ¼òµ¥µÄ¸ÅÄîÌ⣬²»ÖªµÀÔõô×÷´ð£¬¿´À´Òª¶à¶à¹®¹ÌÏÂÀíÂÛ֪ʶÀ²£¡£¡£¡£¡£¡£¡
ÒÔÏÂת:
ÎÒ´Óʼ¼Êõ¹¤×÷£¬
Õ⼸ÄêµÄÃæÊÔÓë±»ÃæÊÔ×ܽá
ÏÈ˵ÎÒÈ¥±»ÃæÊԵľÑé°É¡£
»Ø´ðÇå³þÁË2¸öÎÊÌ⣬¾ÍÄÜ˳Àû¹ý¹ØÁË¡£
1¡£ÎªÊ²Ã´ÒªÀ뿪ÉÏÒ ......
Ô¤´¦ÀíÆ÷£¨Preprocessor£©
1. ÓÃÔ¤´¦ÀíÖ¸Áî#define ÉùÃ÷Ò»¸ö³£Êý£¬ÓÃÒÔ±íÃ÷1ÄêÖÐÓжàÉÙÃ루ºöÂÔÈòÄêÎÊÌ⣩
#define SECONDS_PER_YEAR (60 * 60 * 24 * 365)UL
ÎÒÔÚÕâÏë¿´µ½¼¸¼þÊÂÇ飺
1). #define Óï·¨µÄ»ù±¾ÖªÊ¶£¨ÀýÈ磺²»ÄÜÒԷֺŽáÊø£¬À¨ºÅµÄʹÓ㬵ȵȣ©
2). ¶®µÃÔ¤´¦ÀíÆ÷½«ÎªÄã¼ÆËã³£Êý±í´ïʽµÄÖµ£¬Òò´Ë£¬Ö±½Ó ......
¸Ã³ÌÐòºÜ¼òµ¥£¬¾ÍÊÇÓÃC´ÓORACLE£¬°Ñµ±Ç°ÈÕÆÚÏÔʾ³öÀ´¾ÍOK£¬×÷Ϊһ¸ö¼òµ¥µÄDEMO
£¨Ò»£©Ð´PRO*C
/*===========================================================================
* pro*c±àÒë·½·¨£º
* Ô¤±àÒë proc test.pc
* ±àÒë gcc -o test test.c $ORACLE_HOME/lib/libclntsh.so
* ×÷Õß f ......