How do I access the HTTP Header of request in a CGI script?

前端 未结 3 480
粉色の甜心
粉色の甜心 2020-12-16 11:29

I\'ve used Perl a bit for small applications and test code, but I\'m new to networking and CGI.

I get how to make the header of a request (using CGI.pm and printing

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 12:23

    In addition to the CGI.pm http() method you can get HTTP headers information from the environment variables.

    So in case you are using something like CGI::Minimal, which doesn't have the http method. you can do something like:

      my $header = 'HTTP_X_REQUESTED_WITH';
    
      if (exists $ENV{$header} && lc $ENV{$header} eq 'xmlhttprequest') {
       _do_some_ajaxian_stuff();
      }
    

提交回复
热议问题