Using POST and GET

In PERL, how can I put a GET request, get the results, and parse the results and place a POST request.

I know how to parse and all, but I need to know how to do the GET and POST things.

Tom
LVL 3
TYoungAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TYoungAuthor Commented:
I know you have to use a module, but which one, and what functions do I have to use to do so?
0
ItsMeCommented:
Hi !

This is for get:

     @pairs = split(/&/, $ENV{'QUERY_STRING'});

     foreach $pair (@pairs) {
       ($name, $value) = split(/=/, $pair);
       $value =~ tr/+/ /;
       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
       $value =~ s/~!/ ~!/g;
       $FORM{$name} = $value;
     }

and this for post:

     read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
     @pairs = split(/&/, $buffer);

     foreach $pair (@pairs) {
       ($name, $value) = split(/=/, $pair);
       $value =~ tr/+/ /;
       $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
       $value =~ s/~!/ ~!/g;
       $FORM{$name} = $value;
     }

Hope this is what you wanted to know ?
0
TYoungAuthor Commented:
NO, I mean place another request on another server. My server is http://ubaddon.hypermart.net/. I want my script to call http://www.whatever.com/whatever.pl and get the results.
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

ItsMeCommented:
where do you want to save the results ?
0
ozoCommented:
use LWP::Simple;
$rc = getprint('http://www.whatever.com/whatever.pl');
print status_message($rc);
0
ItsMeCommented:
Hi ozo !
does your solution works with normal files, too ? please check out http://www.experts-exchange.com/jsp/qShow.jsp?ta=cgi&qid=10255159   (100 points)

thanks
ItsMe
0
TYoungAuthor Commented:
Thanx ozo, but how do I make a POST request?
0
clockwatcherCommented:
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;

$ua = new LWP::UserAgent;

# Post parameters
$myparams{"ta"} = "35";
$myparams{"search"} = "LWP";

# Create request
my $req = POST 'http://www.experts-exchange.com/bin/SimpleSearch', [ %myparams ];

# Retrieve the page
$page = $ua->request($req)->as_string;

print $page;
0
TYoungAuthor Commented:
How do I add headers to the POST?
0
TYoungAuthor Commented:
Like User-Agent, Referer, etc.
0
clockwatcherCommented:
Use $req->push_header($name, $value)

E.g.:

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;

$ua = new LWP::UserAgent;

# Post parameters
$myparams{"ta"} = "35";
$myparams{"search"} = "LWP";

# Create request
my $req = POST 'http://www.experts-exchange.com/bin/SimpleSearch', [ %myparams ];

$req->push_header(USER_AGENT => 'Mozilla/2000');
$req->push_header(REFERER => 'www.clickme.com');

# View request
print $req->as_string();

# Retrieve the page
$page = $ua->request($req)->as_string;
print $page;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TYoungAuthor Commented:
This works great. Thanx!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.