HTTP, LWP POSTing

I need to be able to get a form using LWP and POST.    Following the pod, I've got this far, but the script won't compile, complains about Bad Header Type for Content adn Content_Type

 my $ua = LWP::UserAgent->new;
    my $req = HTTP::Request->new(POST => $url,
             Content_Type => 'form-data'                         Content      => [ name  => 'Gisle Aas',
            email => 'gisle@aas.no',
              gender => 'M',
            born   => '1964',
                                     ] );

# content straight from the pod there :)

Error messsage is:
 Carp::croak('Bad header argument') called at lib/HTTP/Message.pm line 52


Any ideas, anyone??

thanks

dave
davet666Asked:
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.

prakashk021799Commented:
# There should be a comma after 'form-data'.
# Is that a typo?

my $req = HTTP::Request->new(POST => $url,
    Content_Type => 'form-data',
    Content      => [ name  => 'Gisle Aas',
                               email => 'gisle@aas.no',
                               gender => 'M',
                               born   => '1964',
                             ] );
0
prakashk021799Commented:
What is line 52 of your script?
0
prakashk021799Commented:
Never mind. The error was talking about line 52 in lib/HTTP/Message.pm
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

davet666Author Commented:
I might actually have got it working (not entirely sure yet).  I gave up on the way the perldoc was suggesting, and am doing it a way I found on anotehr site:

my $ua = new LWP::UserAgent;
    $ua->agent("AgentName/0.1 " . $ua->agent);

    my $req = new HTTP::Request(POST => $url);
    $req->content_type('form-data');
    $req->content($param_string);

    my $res = $ua->request($req);

I'm having more luck with this, but I'm having to build $param_string (param1=val&param2=val2), rather than specifying an array, do you know of a way around this?

0
prakashk021799Commented:
Construct your parameter array like this:

$params = [
    'param1' => val1,
    'param1' => val2,
#  ..... etc.
];

# and then

$req->content($params);
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
davet666Author Commented:
Hey hey, my life is no longer a pit of despair :)  Thank you very much
0
davet666Author Commented:
all sorted! thanks
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.