thdrought has asked for the wisdom of the Perl Monks concerning the following question:
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using the HTTP::Request and Verifying Results
by borisz (Canon) on Oct 12, 2004 at 08:28 UTC | |
|
Re: Using the HTTP::Request and Verifying Results
by BUU (Prior) on Oct 12, 2004 at 09:14 UTC | |
by thdrought (Initiate) on Oct 12, 2004 at 10:20 UTC | |
by borisz (Canon) on Oct 12, 2004 at 10:52 UTC | |
|
Re: Using the HTTP::Request and Verifying Results
by knoebi (Friar) on Oct 12, 2004 at 11:06 UTC |