ArticleDirectory
Refer:
Http://www.willmaster.com/library/manage-forms/using_perl_to_submit_a_form.php
Http://www.oschina.net/code/snippet_12_854
Sometimes you need to call the existing CGI interactively in Perl to complete certain functions. At this time, you need to simulate an HTTP request to call CGI.
Get method call:
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 method call:
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;
Complete!