Hello All,

I am new to programming Perl. I am also new to this site. Found it this morning pulling my hair out over this script that I'm writing. I am hoping someone can help me out, or point me in the right direction.

The script I'm writing is needed to send a request to another website, then receive a response (this I'll be pulling my hair out again...won't have any left after this!). From the other side, they are looking to receive something in the form of (without the comments):

# Start of Sample POST /sample/hello.aspx HTTP/1.0 Host: www.receiver.com Connection: Close Content-type: application/x-www-form-urlencoded Content-Length: 121 ID=Test&Len=121&Data=BlowfishedRealData # End of Sample

I am trying the setup LWP:UserAgent to do this. If I understand correctly, the following code would setup the header and transmit the request, then retreive the results. But, I am unsure of how to test this locally to view the data to be transmitted, with headers, and whether it's 100%. Also, I am receiving the error "Bareword "Content" not allowed while "strict subs"". Why is this a bareword? Why not the others too.

Anyway, here's the code. I'm hoping someone can help this newbie. Thanks.

#!/usr/bin/perl use vars qw( $data $len $pData $ua $req $res ); ( $data, $len, $pData, $ua, $req, $res ) = (); use strict; use LWP::UserAgent; # Create data string, and will eventually be encrypted, but later $data = "BlowfishedRealData"; # Retrieve length of data string $len = length($data); # Creating data - Part 2 $pData = "ID=Test&Len=".$len."&Data=".$data; # Sending the data $ua = LWP::UserAgent->new; $req=HTTP::Request->new(POST => 'http://www.receiver.com/hello.aspx', Host => 'www.receiver.com', Connection => 'Close', Content-type => 'application/x-www-form-urlencoded', Content => [ Data => [$pData] ] ); $res = $ua->request($req); if ($res->is_success) { print $res->as_string; } else { print "Failed: ", $res->status_line, "\n"; }

Tom
"With each day passing, what have you been doing?" Lord Buddha

In reply to Using the HTTP::Request and Verifying Results by thdrought

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.