I'm trying to write a program that sends random variables to an online form and then retrieving the results after the Web server has done the computations. The problem I am having is that I cannot seem to send the details to the form. I tried teh following code:
#!/user/local/bin/perl use strict; use CGI; use HTTP::Request; use LWP::UserAgent; use HTTP::Header; my $start_town = "Guildford"; my $destination_town = "Portsmouth"; my $ua = LWP::UserAgent->new(); my $method = "POST"; my $url = "http://212.87.65.227/bin/query.exe/en"; my $header = HTTP::Header->new(); my $content = "to=".$start_town."&from=".$destination_town; my $request = HTTP::Request->new($method, $url, $header, $content); use HTTP::Response; my $response = $ua->request($request, "page.html"); if($response->is_success) { open PLEASE, "<page.html"; while (<PLEASE>) { print; } close PLEASE; } else { print $response->error_as_HTML; }
But get the following error on running the script:
Can't locate HTTP/Header.pm in @INC (@INC contains: /opt/PDperl/5005_0 +3/lib/5.00 503/sun4-solaris-thread /opt/PDperl/5005_03/lib/5.00503 /opt/PDperl/50 +05_03/lib/ site_perl/5.005/sun4-solaris-thread /opt/PDperl/5005_03/lib/site_perl/ +5.005 .) a t tester3.cgi line 7. BEGIN failed--compilation aborted at tester3.cgi line 7.
From this I assumed that the Web server I am using does not have the Header.pm module. So I tried removing the header line and using the following code:
#!/user/local/bin/perl use strict; use CGI; use HTTP::Request; use LWP::UserAgent; #use HTTP::Header; my $start_town = "Guildford"; my $destination_town = "Portsmouth"; my $ua = LWP::UserAgent->new(); my $method = "POST"; my $url = "http://212.87.65.227/bin/query.exe/en"; #my $header = HTTP::Header->new(); my $content = "to=".$start_town."&from=".$destination_town; my $request = HTTP::Request->new($method, $url, [$content]); use HTTP::Response; my $response = $ua->request($request, "page.html"); if($response->is_success) { open PLEASE, "<page.html"; while (<PLEASE>) { print; } close PLEASE; } else { print $response->error_as_HTML;
But got the following error:
Can't call method "clone" on unblessed reference at /opt/PDperl/5005_0 +3/lib/site _perl/5.005/HTTP/Message.pm line 53.
What is blessing and what variable do I need to bless? Or am I on the wrong track? Any help would be gratefully appreciated. Cobra

In reply to Submitting information to an online form by cobra

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.