Perl Web 服务器初级编程[3]

[入库:2005年8月18日] [更新:2007年3月25日]

本文简介:选择自 nistal 的 blog

                                 while(<>)
                                 {
                                       push @headers,$_    if  1../^$/;
                                       $body.=$_      if /^$/..eof;              #means  $body=$body . $_;
                                  }

                对照:cgi响应是没有状态行的http响应,被要求发送的头有一个是content-type头,后面跟着一个介质类型,以定义主体内容。
                   eg1: print “content-type: text/plain\n\n“;
                   eg2: print “content-type: image/jpeg\n\n”;            
                   
                   cgi环境变量我们可以参考
                     my $docroot=$env {'document_root'};
                  例如我们可以这样查看我们的环境变量:
                    #!/usr/bin/perl -w
                   #author:nick
                   #goal:check the env
                   #env.cgi
                   use strict;
                   print "content-type: text/html \n\n";
                   print "<html><title>enviroment variables</title><head>\n";
                   print "here is your enviroment variables</head>\n" ;
                   print "<body><blockquote><table border=1>\n";
                  foreach (sort keys %env)
                  {
                      print "\t<tr><td> $_ </td><td>$env{$_} </td></tr>\n";
                   }
                    print "</table></blockquote></body></html>\n";
#run the program
#you can see:
#content-length: the length of http requirement,here it should display 0,for we
#did not put or post mainbody here
#gateway-interface: cgi protocol and version
#http-referer: uri of resource
#http_user_agent: client's software,maybe ie or netscape
#path: client's additional path
#query_string: requesting uri's query-string, maybe null or important for cgi
#programs
#remote_addr: client's ip
#remote_host: client's host name

本文关键:Perl Web 服务器初级编程
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top