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

Usage question - not development related

From:
Ken Clarke
Date:
September 5, 2001 11:37
Subject:
Usage question - not development related
Message ID:
006701c13639$32df1100$94c54618@gv.shawcable.net
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 = 'https://anywhere.com/anypath/anypage.anyextension';  # http or
https only
  my @FormData = (F1 => 'V1', F2 => 'V2', F2 => 'V3');  # key repitition
intentional

  # create HTTP header object
  my %HTTPHeaders = (User_Agent => 'My posting engine',
                                          From => 'Email@address.com',
                                          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
redirects?

  # 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
>> www.perlprogrammer.net






nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About