perl中調用cgi

來源:互聯網
上載者:User
文章目錄
  •  

參考:
http://www.willmaster.com/library/manage-forms/using_perl_to_submit_a_form.php 

http://www.oschina.net/code/snippet_12_854 

 

有時需要在perl中非互動地調用已有的cgi來完成一定的功能,此時需要類比一個http請求來調用cgi。

 

get方式調用:

      1 use HTTP::Request::Common;
      2 use LWP::UserAgent;
      3 $user_agent = LWP::UserAgent->new;
      4 $request = GET 'http://clearcase/~xhzhu/cgi/cgireader.cgi?text1=hello&text2=here';
      5 $response = $user_agent->request($request);
      6 print $response->as_string;

post方式調用:

      1 use HTTP::Request::Common;
      2 use LWP::UserAgent;
      3 $user_agent = LWP::UserAgent->new;
      4 $request = POST 'http://clearcase/~xhzhu/cgi/cgireader.cgi',
      5     [text1 => 'Hello', text2 => 'there'];
      6 $response = $user_agent->request($request);
      7 print $response->as_string;

cgireader.cgi:

      1 #!/usr/local/bin/perl
      2 use CGI;
      3
      4 $co = new CGI;
      5
      6 print $co->header,
      7
      8 $co->start_html(
      9     -title=>'CGI Example',
     10     -author=>'yourName',
     11     -BGCOLOR=>'white',
     12     -LINK=>'red'
     13 );
     14
     15 if ($co->param()) {
     16     print
     17         "You entered this text: ",
     18         $co->em($co->param('text1')),
     19         " ",
     20         $co->em($co->param('text2')),
     21         ".";
     22 } else {
     23     print "Sorry, I did not see any text.";
     24 }
     25 print $co->end_html;

 

完! 

 
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.