FORMs , GET requests.....

Hi,

Guess this is pretty easy if you know it....but I don't, so here goes.

All I want to know how to do is to submit a form from a Perl script. I looked at the chapter in Perl Cookbook, but couldn't quite figure out what I was meant to do. The code reads:use

LWP::Simple;
use URI::URL;

my $url = url('http://somewhere.com/index.html');
$url->query_form(module => 'DB_File', readme => 1);
$content = get($url);

How do I put form values into the URL, and how do I tell it where to be submitted to etc, etc. If you can explain what the 'DB_File' bit is above then that would be good too.

So, I want to submit a form to (for example) http://submit-here.com/submitme.cgi and I have a url of http://mydomain.com/index.html and say a couple of form values too, such as e-mail address and name - an expanded explanation would be very appreciated. Thx

D
LVL 1
dgb001Asked:
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.

clockwatcherCommented:
Which method are you looking for (a POST or a GET)?

Here's a POST:

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;

----------------------------------------

Here's a GET:

use LWP::Simple;
$page = get("http://www.experts-exchange.com?ta=35&search=LWP")

print $page;
0
clockwatcherCommented:
Sorry the get is missing a semicolon. :-(

use LWP::Simple;
$page = get("http://www.experts-exchange.com?ta=35&search=LWP");
print $page;
0
dgb001Author Commented:
It's a GET request. I think the bit that is kinda confusing me is how to escape the form variables - I want to be able to pass the url to some routine or something and have it sort out the url - using something like URI::Escape::uri_escape etc, but I haven't the faintest idea how to do that, that's why I really want someone to explain the whole line in the question with DBFILE etc, etc, because I can see that it has something to do with it. Hope you can enlighten me a little further.

Many thx for the help so far,
D
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

clockwatcherCommented:
Either you're making this harder than it is or I don't quite understand your question.

The line in question:

  $url->query_form(module => 'DB_File', readme => 1);

Calls the query_form method of your $url object.  The query_form method escapes the list passed to it and appends it to the base url-- in other words it creates the url's querystring.

The following four lines:

 use URI::URL;
 my $url = url('http://somewhere.com/index.html');
 $url->query_form(module => 'DB_File', readme => 1);
 print "$url\n"

Creates the following URL and prints it to the screen:
 
  http://somewhere.com/index.html?module=DB_File&readme=1


You asked how to submit a form to http://submit-here.com/submitme.cgi with a couple of variables: email and name.

# Create the base url
 
 use URI::URL;
 my $url = url('http://submit-here.com/submitme.cgi');

# Add the querystring with a couple of variables (email and name)
 $url->query_form('email' => 'jdoe@somewhere.com', 'name' => 'John Doe');

# Request the page
 use LWP::Simple;
 $page = get($url);

The code above will retrieve data from the following URL:

  http://submit-here.com/submitme.cgi?email=jdoe%40somewhere.com&name=John%20Doe
0
dgb001Author Commented:
I understand now.....thanks very much. If you post it as an answer I can give you the points. I was just being a bit slow in the head. :-)

Thx,
D
0
clockwatcherCommented:
Thanks
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
dgb001Author Commented:
Sorry clockwatcher, I should really have given you an "A" when I accepted the answer that you gave, you definitely explained it very well to me - apologies, hope I can make it up next time.

D
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.