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

Okay, I guess it is my week to get stumped. I just need another pair of eyes on this code, because I cannot for the life of me figure out what I am doing wrong. According to the docs it is right.

GOAL: trying to use LWP to signin to Amazon to retrieve data off their system

PROBLEM: they set a cookie AND at the same time, use the session id they send in the URL that is the action in the form.

ATTEMPTED METHOD: Use HTTP::Request::Common to POST the data and send the cookies at the same time hoping this will get through.

At this point, I am getting the error that "Can't locate object method "POST" via package "http://www.amazon.com/exec/obidos/flex-sign-in-done/" (perhaps you forgot to load "http://www.amazon.com/exec/obidos/flex-sign-in-done/"?) at ./goldbox.pl line 20" which I do not understand. I am not even sure if the cookies will be sent and the page handled properly, but I can't get past this stupid error message.

#!/usr/local/bin/perl -w use strict; use LWP::UserAgent; use HTTP::Cookies; use HTTP::Request; use HTTP::Headers; my $sessionid; my $browser = LWP::UserAgent->new; my $cookie_locale = "cookies.lwp"; my $cookie_jar = HTTP::Cookies->new( File => $cookie_locale, AutoSave => 1, ); my $email = 'xxxxxxx'; my $password = "xxxxxx"; my $url = "http://www.amazon.com/exec/obidos/flex-sign-in-done/"; my $req = $browser->request(POST $url, [ 'email' => $email, 'action' => 'sign-in checked', 'next-page' => 'recs/instant-recs-sign-in-standard.h +tml', 'password' => $password, 'method' => 'get', 'opt' => 'oa', 'page' => 'recs/instant-recs-register-standard. +html', 'response' => 'tg/stores/static/-/goldbox/index/', 'x' => '22', 'y' => '13', ] ); $cookie_jar->add_cookie_header($req); my $res = $browser->request($req); if ($res->is_success) { print $res->as_string; } else { my $cururl = $res->base->as_string; print "Error: " . $res->status_line . " $cururl\n"; }


I admit it, I am Paco.

Replies are listed 'Best First'.
Re: Sending a POST and cookies via HTTP:Request::Common
by blm (Hermit) on Sep 28, 2002 at 08:20 UTC

    May I suggest you look at Re: POSTing with LWP::UserAgent as it has two ways of posting forms with LWP.

    In short I think the first step is that you need to import the POST sub into the namespace using:

    use HTTP::Request::Common qw(POST);
    --blm--
    If you don't like this post can you please /msg me
      That does not appear to be in the docs, but I should have know. Thanks.


      I admit it, I am Paco.
Re: Sending a POST and cookies via HTTP:Request::Common
by cmmdrdata (Initiate) on Dec 23, 2003 at 00:09 UTC
    I have almost exactly the same code as you mentioned above and I am getting the following error. Can't locate object method "url" via package "HTTP::Headers" (perhaps you forgot to load "HTTP::Headers"?) at (eval 16) line 1. Yes, I have the line use HTTP::Headers. What else could be wrong here? HELP!!!!
      Okay I have copied the exact code from the above, included the POST in the namespace.
      I still get an error that I don't understand

      Can't locate object method "url" via package "HTTP::Headers" at /opt/local/lib/perl5/site_perl/5.005/HTTP/Message.pm line 186.

      Can someone PLEASE help with this?
      I am using perl 5.005_02 built for PA-RISC1.1