Forum Moderators: coopster & phranque

Message Too Old, No Replies

LWP::UserAgent submitting a form

         

Reynolds

1:37 pm on Oct 10, 2001 (gmt 0)

10+ Year Member



Hello,

I use a function in many perl scripts that will submit a form.

It works very well. *Except for when you try to submit a form where the URL has a hyphen (-) in it.

Why is that? Does anyone know?

Here is the function I use to submit a form.

sub submit_form {
print "Content-type: text/html\n\n";
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;

$ua = LWP::UserAgent->new();
my $req = POST 'http://www.domain-name.com/cgi-bin/script.pl',
[ first_name => $firstname, email => $email];

$content = $ua->request($req)->as_string;

print "content = $content";

}

It works great. But, notice how the URL is "domain-name"?

For some reason, it doesn't like this. If the URL is "domainname", it works.

I've tried placing an escape "\" character before it.

If anyone has *any* ideas I would be very grateful.

Thank you
Eric Reynolds

sugarkane

7:29 pm on Oct 10, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hmm, it all looks like it *should* work, but I've not really played around with POST. I can only think it might be a bug in HTTP::Request::Common - does it work if you use the long way round?

[perl]
use LWP::UserAgent;
$ua = new LWP::UserAgent;

my $req = new HTTP::Request 'POST','http://www.domain-name.com/cgi-bin/script.pl';
$req->content_type('application/x-www-form-urlencoded');
$req->content('first_name=$firstname&email=$email');

my $content = $ua->request($req)->as_string;
[/perl]

(If you do it this way you'll have to use URI::Escape on the parameters you're passing)