develooper Front page | perl.libwww | Postings from September 2001

Usage question - not development related

Ken Clarke
September 5, 2001 11:37
Usage question - not development related
Message ID:
Hi Folks,

    I realize that this is a developers list, so this post may not be
appropriate.  My apologies in advance for the extra clutter and my thanks
for your work on this incredible bundle of modules.  If any of you would
like a small consulting job supporting my development of this script, please
contact me directly.

    I'm developing a multi-website posting engine and am somewhat confused
by the interdependancies of the various modules.  Does this script snippet
seem correct?


  # initalize variables (these 3 are actually sent to a subroutine which
contains the request snippet)
  my $Method = 0;  # 0 indicates GET, 1 indicates POST
  my $URL = '';  # http or
https only
  my @FormData = (F1 => 'V1', F2 => 'V2', F2 => 'V3');  # key repitition

  # create HTTP header object
  my %HTTPHeaders = (User_Agent => 'My posting engine',
                                          From => '',
                                          Accept => 'text/html');
  my $headers = HTTP::Header -> new(\%HTTPHeaders);

  # create request object
  if ($Method) {  # METHOD is POST
       $req = HTTP::Request -> new('POST', $URL, $headers, \@FormData);
  } else {  # METHOD is GET
       $req = HTTP::Request -> new('GET', $URL, $headers);
       $req -> query_form(\@FormData);

  # create User Agent
  my $postengine = LWP::UserAgent->new();
  $postengine -> cookie_jar($Cookies);  # mirror cookies - $Cookies is an
HTTP::Cookies object
  # push @{ $postengine -> requests_redirectable }, $Method;  # support

  # add login and file upload capabilities if appropriate
  if ($HeaderDataPointer) {  # this is simply the string 0 (zero) if nothing
is supplied
      $postengine -> authorization_basic($$HeaderDataPointer{'username'},
$$HeaderDataPointer{'password'}) if
$$HeaderDataPointer{'authorization_basic'};  # handle login if req'd
     $req -> Content_Type('form-data') if
(exists($$HeaderDataPointer{'enctype'}));  # if uploading a file


    Any comments are appreciated.

    One other question:  If the response is a redirect, should I resend the
form data or will "push @{ $postengine -> requests_redirectable }, $Method;"
handle this internally?

    Thanks for your time.

>> Ken Clarke
>> Contract Web Programmer / E-commerce Technologist
>> Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About