tags:

views:

135

answers:

1

i write this perl code :

use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
my $ua = LWP::UserAgent->new();
my $req = POST 'http://example.com',
[ hfc /[pos]/ => 'yayaya' ];
$content = $ua->request($req)->as_string; 

but when i compile it i get this error :

syntax error at C:\Documents and Settings\ysys\ya.pl line 5, near "/ =>"

what am i going to do ? Thanks in Advance .

+1  A: 

I think this is what she wants:

use LWP::UserAgent; 
my $ua = new LWP::UserAgent;

#this should work
my $response = $ua->post('http://www.example.com', ["hfc[pos]" => 'yayaya']);    
my $content = $response->content; 

This is how you use post(): $ua->post( $url, $field_name => $value,...)

By the way when you read documentation and it says something like:

$ua->request($request, $arg [, $size])

It just means that the $size argument is optional. You must NOT include the brackets [ ] in your code.

NullUserException
Thanks for your answer . but name of the text field is : Name = "hfc[pos]" and when i want send it by parameter i must do : hfc/[pos]/ => 'yaya' and i get error . Thanks again .
Jessica
@Jessica Use a backslash \ to escape characters.
NullUserException
may you give me an example ?
Jessica
@Jessica I don't think you need to escape brackets. I edited the example. I tested the code and it works.
NullUserException