about CGI & debug【求助】



贊助商連結


jackiemi2
2003-04-09, 06:07 PM
各位大大!
小弟最近在寫CGI, 我用的Web server 是thttpd, 寫CGI的tool是C language, 小弟遇到了幾個瓶頸,browser按了個submit的鍵後, Web server處理CGI程式, Server會丟字串回去給browser, 但browser顯示出來是空白的網頁, 我用sniffer去捉傳回的封包,發現回傳的封包是空白的, 裡面也沒有記錄thttpd server版本, 我的"猜測"如下:
1.是CGI程式錯誤, 或Web server根本沒處理CGI程式, 或有處理後沒將CGI處理後的結果傳回給browser, 我試著用GDB去debug程式, 但程式是沒問題的, 有沒有大大試過在Linux上捉web server處理封包的軟體, 我試過去browser在web server放CGI的目錄/cgi-bin, 裡面我放文字檔, html檔, 和CGI的檔, 我點選後文字檔和html檔都在client的browser可以show出, 但CGI檔打開了就是空白
2.我的web server(Thttpd)沒架好, 導致沒去處理CGI的程式
小弟我附上我的程式和thttpd.conf及thttpd.log請各位大大能幫幫我! 感恩!

Hello.c程式如下:
#include <stdio.h>

int
main( int argc, char** argv )
{
fputs( "Content-type: text/plain\n\nHello.\n", stdout );
exit( 0 );
}

thttpd.conf如下:
# BEWARE : No empty lines are allowed!
# This section overrides defaults
dir=/var/www
chroot
cgipat=**.cgi
logfile=/var/www/logs/thttpd.log
pidfile=/var/run/thttpd.pid
# This section _documents_ defaults in effect
# port=80
# nosymlink # default = !chroot
# novhost
# nocgipat
# nothrottles
# host=0.0.0.0
#charset=iso-8859-1

thttpd.log如下:
192.168.0.146 - - [09/Apr/2003:16:56:27 +0800] "GET /cgi-bin/hello_cgi.cgi HTTP/1.1" 200 50000 "http://192.168.0.147/cgi-bin/" "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0; KKman2.0)"