saab99e has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I am trying to use HTTP::Request::Common;
Its working fine but I want to make the code more generic ... I am POSTing a request with:

my $req = POST $url, Content_Type => 'form-data', Content => [ loaderid => $loaderid, zipped => $zipped, user => $user, filetype => $filetype, file => [ $fname ] ];

What I want to do is have variable number of attributes that I read from a config file such as:

#################### # Load Settings # #################### loaderid = 382 user = Andy zipped = 1 # 0 Not Zipped, 1 Zipped, 2 Gzipped- do not use -1 filetype = 1 # 1 = Measurements, 2 = Outage, 3 = Rotation

Using the following code...

while (<CONFIG>) { chomp; # no newline s/#.*//; # no comments s/^\s+//; # no leading white s/\s+$//; # no trailing white next unless length; # anything left? my ($var, $value) = split(/\s*=\s*/, $_, 2); $preferences{$var} = $value; }

The problem is that I don't know how to allocate variable attibutes in the Content part of the request... really its a formtting/syntax problem more than anything else.

Essentially, I want changes in the config file to be reflected in the POST ... if that makes sense!!!

All assistance would be greatly appreciated.

Andy

Replies are listed 'Best First'.
Re: Variable HTTP request.
by Corion (Patriarch) on Sep 29, 2010 at 11:11 UTC

    Just put your additional arguments into the request:

    my $req = POST $url, Content_Type => 'form-data', Content => [ loaderid => $loaderid, zipped => $zipped, user => $user, filetype => $filetype, file => [ $fname ] %preferences, ];
      Thanks as usual a very simple solution! Andy