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.

In reply to Re: How to POST to a web server? by Incognito
in thread How to POST to a web server? by Cheburashka

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.