Kyle R . Burton on Mon, 17 Jun 2002 14:25:09 -0400


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] capture browser request


>   sub post
>   {
>     my($self,$url,%params) = @_;
>     my $req = HTTP::Request->new( 'POST', $url );
>     foreach my $p (keys %params) {
>       $req->add_content( uri_escape($p)."=".uri_escape($params{$p}||'') );
>     }
>     return $self->request( $req );
>   }

> (yes, I did run this code before I cut and pasted it into mutt, so it
> does work)

Ok, I _didn't_ test the post method...that should look something more
along the lines of:

  sub post
  {
    my($self,$url,%params) = @_;
    my $req = HTTP::Request->new( 'POST' => $url );
    my @data;
    foreach my $k (keys %params) {
      push @data, uri_escape($k)."=".uri_escape($params{$k}||'');
    }
    $req->add_content( join("&", @data) );
    $req->content_length(length($req->content()));
    $req->content_type('application/x-www-form-urlencoded');
    return $self->request( $req );
  }

Which you can test by changing the original 'main' to:

  package main;
  use strict;
  use warnings;
  my $ua = EasierUA->new();
  #my $resp = $ua->get( 'http://www.yahoo.com/' );
  my $resp = $ua->post(
    'http://www.altavista.com/sites/search/res_text',
    'sc'     => 'on',
    'avkw'   => 'tgz',
    'hl'     => 'on',
    'amb'    => 'txt',
    'q'      => 'asdf',
    'kl'     => 'XX',
    'search' => 'Search',
  );
  print $resp->content();

Sorry for posting non-working code and telling you it worked :)

Kyle


-- 

------------------------------------------------------------------------------
Wisdom and Compassion are inseparable.
        -- Christmas Humphreys
mortis@voicenet.com                            http://www.voicenet.com/~mortis
------------------------------------------------------------------------------

______________________________________________________________________
Philadelphia Linux Users Group       -      http://www.phillylinux.org
Announcements-http://lists.phillylinux.org/mail/listinfo/plug-announce
General Discussion  -  http://lists.phillylinux.org/mail/listinfo/plug