Cheburashka has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's minimum standard of quality and will not be displayed.

Replies are listed 'Best First'.
Re: Hello
by lostcause (Monk) on Nov 17, 2001 at 02:02 UTC
Re: Hello
by kwoff (Friar) on Nov 17, 2001 at 01:32 UTC
    Read `perldoc LWP`. It rox.
(shockme) Re: Hello
by shockme (Chaplain) on Nov 17, 2001 at 08:03 UTC
    Here's a section of code used to retrieve a page from my DSL modem. Maybe it'll help get you started.
    #!/usr/bin/perl open(OUT, ">/tmp/cayman.html" || die "can't open output"); use LWP::UserAgent; $ua = LWP::UserAgent->new; $req = HTTP::Request->new(GET => "http://192.168.1.254:8080/shell/show ++ip+interfaces"); $req->authorization_basic("userid", "password"); $response = $ua->request($req); $content = $response->content(); print OUT $content; close(OUT) || die "can't close output cayman.html";
Re: Hello
by data64 (Chaplain) on Nov 17, 2001 at 05:55 UTC
    How about using a more descriptive name ? Hello doesn't really say much, does it ?
Re: How to POST to a web server?
by Incognito (Pilgrim) on Nov 21, 2001 at 02:04 UTC
    I believe what you are trying to do is make a POST to a web page, and then view or store the returned page... This is a straightforward problem and here is the Perl code that will do this:

    http_post.pl

    #!/usr/bin/perl -w use strict 'subs'; use LWP::UserAgent; BEGIN { $ENV{PATH} = '/usr/bin:/bin' } require LWP::UserAgent; $URL = "http://localhost/Test.asp"; print "Posting to the page '$URL'.\n"; ($returnedPage) = DoPost ($URL); print "Dispaying POSTed results:\n"; print "="x72."\n$returnedPage\n"."="x72."\n"; exit; sub DoPost { local ($url) = @_; use HTTP::Request::Common qw(POST); use LWP::UserAgent; my $browserType = "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5. +0)"; my $httpReferer = "http://www.PerlMonks.org"; my $userAgent = new LWP::UserAgent; $userAgent->agent("$browserType "); my $request = POST "$url", [ Value1 => 'Some value for 1', Value2 => 'My value 2 result', Value3 => 'My value 3' ]; $request->referer("$httpReferer"); # Post the request to the server my $response = $userAgent->request($request)->as_string; return ($response); }

    Test.asp

    Take the code below and rename it "test.asp" off the root of your web server (running IIS) to verify that the contents you POSTed to the web page are in fact being accepted by the page you are submitting to:
    This page writes out POSTed FORM values: <P> <% Call WriteQueryStringContents() Sub WriteQueryStringContents Dim strItem Response.Write CHR(10) & "<P>" & CHR(10) Response.Write "QueryString contents:" & CHR(10) For Each strItem In Request.QueryString Response.Write "<LI>" & strItem & ": " Response.Write Request.QueryString(strItem) & "</LI>" & CHR(10 +) Next Response.Write CHR(10) & "<P>" & CHR(10) Response.Write "Form contents:" & CHR(10) For Each strItem In Request.Form Response.Write "<LI>" & strItem & ": " Response.Write Request.Form(strItem) & "</LI>" & CHR(10) Next End Sub %> </P>

    Example

    Here's the results we get when we run this simple Perl program:
    E:\Personal>perl http_post.pl Posting to the page 'http://localhost/Test.asp'. Dispaying POSTed results: ====================================================================== +== HTTP/1.1 200 OK Cache-Control: private Connection: Keep-Alive Date: Tue, 20 Nov 2001 20:54:11 GMT Server: Microsoft-IIS/5.0 Content-Length: 201 Content-Type: text/html Client-Date: Tue, 20 Nov 2001 20:54:11 GMT Client-Peer: 127.0.0.1:80 Set-Cookie: ASPSESSIONIDQGGGQNOK=LEDDBLNAMNEONOJLKHFDFANJ; path=/ This page writes out POSTed FORM values: <P> <P> QueryString contents: <P> Form contents: <LI>Value1: Some value for 1</LI> <LI>Value2: My value 2 result</LI> <LI>Value3: My value 3</LI> </P> ====================================================================== +==
    As you can see, the three values we POSTed to the page Test.asp were successfully received and displayed.