Code Comments
Programming Forum and web based access to our favorite programming groups.Hello everyone, I am a newbie to the world of CGI/Perl. I have a following situation. Running apache 2.0.43 - wrote a perl script that does the following.. exerpt from post.pl file my $form = [ "USER" => $userId, "username" => $username, "partition" => $partition, "itemID" => $itemID, "page" => $page] my $myURL = "http://myhost.com"; my $userAgent = new LWP::UserAgent(); my $request = HTTP::Request::Common::POST($myURL, $form); my $response = $userAgent->request($request); my $responseString = $response->as_string; print $responseString; Everything is happy accept that with HTTP POST - I do not get redirected to the resulting page - I still stay on post.pl file. If you post to any page - you should ideally get redirected to where you posted to. Am I doing anything wrong here? How can I get around this problem? Thanks Jaimin
Post Follow-up to this messageJust Curious wrote: > > I am a newbie to the world of CGI/Perl. If you are new to CGI, HTML, HTTP and Perl all at the same time you will need to work extra hard to be sure which one you are dealing with at any given moment. Not only is it a vital first step to solving problems for yourself but it also creates bad feeling if you post a pure CGI question to a Perl newsgroup or vice versa. > I have a following situation. > Running apache 2.0.43 - wrote a perl script that does the following.. > > exerpt from post.pl file > > my $form = [ "USER" => $userId, > "username" => $username, > "partition" => $partition, > "itemID" => $itemID, > "page" => $page] > > my $myURL = "http://myhost.com"; > > my $userAgent = new LWP::UserAgent(); > > my $request = HTTP::Request::Common::POST($myURL, $form); > my $response = $userAgent->request($request); > my $responseString = $response->as_string; > print $responseString; > > Everything is happy accept that with HTTP POST - I do not get > redirected to the resulting page - I still stay on post.pl file. You appear to be confusing CGI and LWP. LWP is a web client written on Perl. It communicated with a web server elsewhere using HTTP. CGI is an API used to communicate between an web server process and a script providing dynamic content on that server. The Perl module also called CGI is a Perl wrapper for the CGI API. > If you post to any page - you should ideally get redirected to where > you posted to. If the remote server at myhost.com is responding with a redirect then maybe you could catch that and pass it on (but you'd have to tell LWP::UserAgent not to try to follow the redirect first). If the redirect is relative you'd need to make it absolute. > Am I doing anything wrong here? It is possible that you have completely the wrong mental model of the HTTP cycle. > How can I get around this problem? You would need to learn about HTTP (this has nothing to do with Perl or CGI). You may find the Content-Location header helps. Then again you may not.
Post Follow-up to this messageJust Curious wrote: > > I am a newbie to the world of CGI/Perl. If you are new to CGI, HTML, HTTP and Perl all at the same time you will need to work extra hard to be sure which one you are dealing with at any given moment. Not only is it a vital first step to solving problems for yourself but it also creates bad feeling if you post a pure CGI question to a Perl newsgroup or vice versa. > I have a following situation. > Running apache 2.0.43 - wrote a perl script that does the following.. > > exerpt from post.pl file > > my $form = [ "USER" => $userId, > "username" => $username, > "partition" => $partition, > "itemID" => $itemID, > "page" => $page] > > my $myURL = "http://myhost.com"; > > my $userAgent = new LWP::UserAgent(); > > my $request = HTTP::Request::Common::POST($myURL, $form); > my $response = $userAgent->request($request); > my $responseString = $response->as_string; > print $responseString; > > Everything is happy accept that with HTTP POST - I do not get > redirected to the resulting page - I still stay on post.pl file. You appear to be confusing CGI and LWP. LWP is a web client written on Perl. It communicated with a web server elsewhere using HTTP. CGI is an API used to communicate between an web server process and a script providing dynamic content on that server. The Perl module also called CGI is a Perl wrapper for the CGI API. > If you post to any page - you should ideally get redirected to where > you posted to. If the remote server at myhost.com is responding with a redirect then maybe you could catch that and pass it on (but you'd have to tell LWP::UserAgent not to try to follow the redirect first). If the redirect is relative you'd need to make it absolute. > Am I doing anything wrong here? It is possible that you have completely the wrong mental model of the HTTP cycle. > How can I get around this problem? You would need to learn about HTTP (this has nothing to do with Perl or CGI). You may find the Content-Location header helps. Then again you may not.
Post Follow-up to this messageGee whiz! How about this simple script below? use LWP::UserAgent; use HTTP::Request; "Brian McCauley" <nobull@mail.com> wrote in message news:cgnotl$sfs$1@sun3.bham.ac.uk... > > > Just Curious wrote: > > If you are new to CGI, HTML, HTTP and Perl all at the same time you will > need to work extra hard to be sure which one you are dealing with at any > given moment. Not only is it a vital first step to solving problems for > yourself but it also creates bad feeling if you post a pure CGI > question to a Perl newsgroup or vice versa. > > > You appear to be confusing CGI and LWP. > > LWP is a web client written on Perl. It communicated with a web server > elsewhere using HTTP. > > CGI is an API used to communicate between an web server process and a > script providing dynamic content on that server. The Perl module also > called CGI is a Perl wrapper for the CGI API. > > > If the remote server at myhost.com is responding with a redirect then > maybe you could catch that and pass it on (but you'd have to tell > LWP::UserAgent not to try to follow the redirect first). If the > redirect is relative you'd need to make it absolute. > > > It is possible that you have completely the wrong mental model of the > HTTP cycle. > > > You would need to learn about HTTP (this has nothing to do with Perl or > CGI). > > You may find the Content-Location header helps. Then again you may not. >
Post Follow-up to this messageGee whiz! Jaimin: How about this very simple script below? use LWP::UserAgent; use HTTP::Request; my $userAgent = new LWP::UserAgent(); my $res = $userAgent->post( $myURL, 'Content-Type' => "bla bla bla", Content => [ 'USER' => $userId, 'username' => $username, etc. ] ); $response->as_string; BG "Brian McCauley" <nobull@mail.com> wrote in message news:cgnotl$sfs$1@sun3.bham.ac.uk... > > > Just Curious wrote: > > If you are new to CGI, HTML, HTTP and Perl all at the same time you will > need to work extra hard to be sure which one you are dealing with at any > given moment. Not only is it a vital first step to solving problems for > yourself but it also creates bad feeling if you post a pure CGI > question to a Perl newsgroup or vice versa. > > > You appear to be confusing CGI and LWP. > > LWP is a web client written on Perl. It communicated with a web server > elsewhere using HTTP. > > CGI is an API used to communicate between an web server process and a > script providing dynamic content on that server. The Perl module also > called CGI is a Perl wrapper for the CGI API. > > > If the remote server at myhost.com is responding with a redirect then > maybe you could catch that and pass it on (but you'd have to tell > LWP::UserAgent not to try to follow the redirect first). If the > redirect is relative you'd need to make it absolute. > > > It is possible that you have completely the wrong mental model of the > HTTP cycle. > > > You would need to learn about HTTP (this has nothing to do with Perl or > CGI). > > You may find the Content-Location header helps. Then again you may not. >
Post Follow-up to this messageGee whiz! Jaimin: How about this very simple script below? use LWP::UserAgent; use HTTP::Request; my $userAgent = new LWP::UserAgent(); my $res = $userAgent->post( $myURL, 'Content-Type' => "bla bla bla", Content => [ 'USER' => $userId, 'username' => $username, etc. ] ); $response->as_string; BG "Brian McCauley" <nobull@mail.com> wrote in message news:cgnotl$sfs$1@sun3.bham.ac.uk... > > > Just Curious wrote: > > If you are new to CGI, HTML, HTTP and Perl all at the same time you will > need to work extra hard to be sure which one you are dealing with at any > given moment. Not only is it a vital first step to solving problems for > yourself but it also creates bad feeling if you post a pure CGI > question to a Perl newsgroup or vice versa. > > > You appear to be confusing CGI and LWP. > > LWP is a web client written on Perl. It communicated with a web server > elsewhere using HTTP. > > CGI is an API used to communicate between an web server process and a > script providing dynamic content on that server. The Perl module also > called CGI is a Perl wrapper for the CGI API. > > > If the remote server at myhost.com is responding with a redirect then > maybe you could catch that and pass it on (but you'd have to tell > LWP::UserAgent not to try to follow the redirect first). If the > redirect is relative you'd need to make it absolute. > > > It is possible that you have completely the wrong mental model of the > HTTP cycle. > > > You would need to learn about HTTP (this has nothing to do with Perl or > CGI). > > You may find the Content-Location header helps. Then again you may not. >
Post Follow-up to this messageGee whiz! How about this simple script below? use LWP::UserAgent; use HTTP::Request; "Brian McCauley" <nobull@mail.com> wrote in message news:cgnotl$sfs$1@sun3.bham.ac.uk... > > > Just Curious wrote: > > If you are new to CGI, HTML, HTTP and Perl all at the same time you will > need to work extra hard to be sure which one you are dealing with at any > given moment. Not only is it a vital first step to solving problems for > yourself but it also creates bad feeling if you post a pure CGI > question to a Perl newsgroup or vice versa. > > > You appear to be confusing CGI and LWP. > > LWP is a web client written on Perl. It communicated with a web server > elsewhere using HTTP. > > CGI is an API used to communicate between an web server process and a > script providing dynamic content on that server. The Perl module also > called CGI is a Perl wrapper for the CGI API. > > > If the remote server at myhost.com is responding with a redirect then > maybe you could catch that and pass it on (but you'd have to tell > LWP::UserAgent not to try to follow the redirect first). If the > redirect is relative you'd need to make it absolute. > > > It is possible that you have completely the wrong mental model of the > HTTP cycle. > > > You would need to learn about HTTP (this has nothing to do with Perl or > CGI). > > You may find the Content-Location header helps. Then again you may not. >
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.