We Recommend

Learning Perl Learning Perl
In this smooth, carefully paced course, a leading Perl trainer teaches you to program in the language that threatens to make C, sed, awk, and the Unix shell obsolete for many tasks. This book is the "official" guide for both formal (classroom) and informal learning. It is fully accessible to the novice programmer.


Posted By

noah on 07/03/07


Tagged

forms web lwp automation productivity agent spoof


Versions (?)


submit a POST query with parameters


Published in: Perl 


from The Perl Black Book, Holzner, p. 1247

  1. #! /usr/bin/perl -w
  2. use strict;
  3. use HTTP::Request::Common;
  4. use LWP::UserAgent;
  5. #The Perl Black Book, Holzner, p. 1247
  6.  
  7.  
  8. =item how to call submit_query():
  9. #Method 1.
  10. my %example = (test1 => 'noah', test2 => 'sussman');
  11. submit_query("http://suburbanangst.com/reg.php", %example);
  12.  
  13. #Method 2.
  14. submit_query("http://suburbanangst.com/reg.php?test1=foo&test2=bar;");
  15. =cut
  16.  
  17. sub submit_query {
  18. my ($file, %query) = @_;
  19. my $user_agent = LWP::UserAgent->new;
  20. $user_agent->agent("MSIE/5.5 " . $user_agent->agent);
  21. my $request = POST
  22. #'http://suburbanangst.com/reg.php',
  23. $file,
  24. [%query];
  25. my $response = $user_agent->request($request);
  26. print $response->as_string;
  27. }

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: r03rjwalton on July 4, 2007

hi

Posted By: r03rjwalton on July 4, 2007

hi it john

You need to login to post a comment.