Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Error! Clone on unblessed reference

by Agyeya (Hermit)
on May 20, 2004 at 04:38 UTC ( [id://354860]=perlquestion: print w/replies, xml ) Need Help??

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

Fellow monks
I have writtent the following program to go through three webpages that have javascript and then to download the third page for further processing.
But on executing the code i am getting the following error.
Can't call method "clone" on unblessed reference at /usr/lib/perl5/site_perl/5.8.0/HTTP/Message.pm line 22.
My program is to obtain the third page and to store it into "cal.html". Could anybody help me out, as to what this error is and how i could rectify it. My code is as follows
#!/usr/bin/perl # Stats.plx use warnings; use strict; use WWW::Mechanize; use File::Basename; use DBI; use Date::Manip; use Template::Extract; use Data::Dumper; my ($agent,$request,$post_args); $agent = WWW::Mechanize->new( autocheck => 1 ); $request = new HTTP::Request('GET' => "http://www.abc.com/ChooseZone.a +spx?type=A"); print "Making HTTP Post Request....\n"; $request = new HTTP::Request('POST' => "http://www.abc.com/ChooseZone. +aspx?type=A" , [ '__EVENTTARGET' => "rdlZone_0", '__EVENTARGUMENT' => "", '__VIEWSTATE' => "dDw0NzUyOTE0NzQ7dDw7bDxpPDE+Oz47bDx0PDtsPGk8MT47 +aTwzPjs+O2w8dDw7bDxpPDA+Oz47bDx0PDtsPGk8MD47PjtsPHQ8O2w8aTwwPjtpPDE+O +z47bDx0PDtsPGk8MT47PjtsPHQ8cDxwPGw8VGV4dDs+O2w8UGxlYXNlIFNlbGVjdCB0aG +UgQ29uc3VsYXIgRGlzdHJpY3QgdGhhdCBjb3ZlcnMgeW91ciBSZXNpZGVuY2U7Pj47Pjs +7Pjs+Pjt0PDtsPGk8MT47PjtsPHQ8cDxwPGw8VGV4dDs+O2w8VFQgU2VydmljZXMgLSBX +ZWIgQXBwbGljYXRpb247Pj47Pjs7Pjs+Pjs+Pjs+Pjs+Pjt0PHQ8O3A8bDxpPDA+O2k8M +T47aTwyPjs+O2w8cDxcPC90ZFw+XDx0ZCB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hbmQgTmljb2JhciBJc2xhbmRzIFw8L +1REXD5cPFREXD47Mz47Pj47Pjs7Pjs+Pjs+Pjs+ES4L3Lspgy7Nq0zptOk6nJmcTfM=", 'rdlZone' => "1", ] ); $post_args = { }; $post_args->{'rdlZone'} = "1"; # was "" $post_args->{'__EVENTTARGET'} = "rdlZone_0"; # was "" $request = new HTTP::Request('GET' => "http://www.abc.com/ChooseVisa.a +spx"); $agent->get("http://www.abc.com/CalendarDisp.aspx", ":content_file" => "cal.html" );

Replies are listed 'Best First'.
Re: Error! Clone on unblessed reference
by saskaqueer (Friar) on May 20, 2004 at 05:03 UTC

    First of all, you're never actually executing the requests that you are building (unless you decided not to post that part of the code here). I'm not exactly sure how you do it with WWW::Mechanize, but I think it has something to do with calling $agent->request( $request ); (I know that WWW::Mechanize is a subclass of LWP::UserAgent, so it should be about the same).

    Anyhow, HTTP::Request doesn't take a reference (array or hash) for the headers. Do this instead:

    $request = HTTP::Request->new( 'GET' => 'http://www.abc.com/ChooseZone.aspx?type=A' ); $request->header( '__EVENTTARGET' => 'rdlZone_0', '__EVENTARGUMENT' => '', '__VIEWSTATE' => 'super_long_text', 'rdlZone' => '1', );
What does Foo->bar( [ $url [, $user [, $pass ]]]) mean?
by PodMaster (Abbot) on May 21, 2004 at 04:39 UTC
    I forget where this is documented (i'm not on my regular machine so I can't look it up), but in documentation
    Foo->bar( [ $url [, $user [, $pass ]]])
    usually means that Foo->bar() takes none, or at most three arguments, as in Foo->bar() or Foo->bar($url) or Foo->bar($url, $user) or Foo->bar($url, $user, $pass). [] means optional argument.

    MJD says "you can't just make shit up and expect the computer to know what you mean, retardo!"
    I run a Win32 PPM repository for perl 5.6.x and 5.8.x -- I take requests (README).
    ** The third rule of perl club is a statement of fact: pod is sexy.

Re: Error! Clone on unblessed reference
by Agyeya (Hermit) on May 26, 2004 at 08:26 UTC
    The problem with my above code (if I am not wrong) is that
    1) I have used two modules - WWW::Mechanize and HTTP::Request.
    2) I have set the cookie with the HTTP::Request module and downloaded the web page by the Mechanize object.
    It is for this reason that my downloaded page was showing "Your session has expired."

    I have made some changes to my program but still the problem persists.(session expired)
    The complete changed program is as below.
    #!/usr/bin/perl # Stats.plx use warnings; use strict; use WWW::Mechanize; use File::Basename; use DBI; use Date::Manip; use Template::Extract; use Data::Dumper; my $agent; $agent = WWW::Mechanize->new( autocheck => 1 ); $agent->get("http://www.abc.com/ChooseZone.aspx?type=A"); print "Making HTTP Post Request....\n"; $agent->get("http://www.abc.com/ChooseZone.aspx?type=A &__EVENTTARGET= +rdlZone_0 &__EVENTARGUMENT= &__VIEWSTATE='dDw0NzUyOTE0NzQ7dDw7bDxpPDE ++Oz47bDx0PDtsPGk8MT47aTwzPjs+O2w8dDw7bDxpPDA+Oz47bDx0PDtsPGk8MD47Pjts +PHQ8O2w8aTwwPjtpPDE+Oz47bDx0PDtsPGk8MT47PjtsPHQ8cDxwPGw8VGV4dDs+O2w8U +GxlYXNlIFNlbGVjdCB0aGUgQ29uc3VsYXIgRGlzdHJpY3QgdGhhdCBjb3ZlcnMgeW91ci +BSZXNpZGVuY2U7Pj47Pjs7Pjs+Pjt0PDtsPGk8MT47PjtsPHQ8cDxwPGw8VGV4dDs+O2w +8VFQgU2VydmljZXMgLSBXZWIgQXBwbGljYXRpb247Pj47Pjs7Pjs+Pjs+Pjs+Pjs+Pjt0 +PHQ8O3A8bDxpPDA+O2k8MT47aTwyPjs+O2w8cDxcPC90ZFw+XDx0ZCB3aWR0aD0nMjUlJ +2NsYXNzPSdCb2R5VGV4dCdcPlw8Ylw+VVMgQ29uc3VsYXRlIENoZW5uYWkgKE1hZHJhcy +lcPC9iXD5cPC90ZFw+XDx0ZCBjbGFzcz0nQm9keVRleHQnXD4gQ292ZXJzIHJlc2lkZW5 +0cyBvZiB0aGUgc291dGhlcm4gc3RhdGVzIG9mIEFuZGhyYSBQcmFkZXNoLCBLZXJhbGEs +IFRhbWlsIE5hZHUsIEthcm5hdGFrYSwgTGFrc2hhZHdlZXAgSXNsYW5kcyBhbmQgUG9uZ +GljaGVycnkuXDwvdGRcPlw8dGRcPjsxPjtwPFw8L3RkXD5cPFREIHdpZHRoPScyNSUnY2 +xhc3M9J0JvZHlUZXh0J1w+XDxiXD5VUyBFbWJhc3N5IE5ldyBEZWxoaVw8L2JcPlw8L1R +EXD5cPFREIGNsYXNzPSdCb2R5VGV4dCdcPiBDb3ZlcnMgcmVzaWRlbnRzIG9mIERlbGhp +IGFuZCB0aGUgbm9ydGggSW5kaWFuIHN0YXRlcyBvZiBIYXJ5YW5hLCBIaW1hY2hhbCBQc +mFkZXNoLCBKYW1tdSAmIEthc2htaXIsIFB1bmphYiwgUmFqYXN0aGFuLCBVdHRhciBQcm +FkZXNoIGFuZCBVdHRhcmFuY2hhbC5cPC9URFw+XDxURFw+OzI+O3A8XDwvVERcPlw8VEQ +gd2lkdGg9JzI1JSdjbGFzcz0nQm9keVRleHQnXD5cPGJcPlVTIENvbnN1bGF0ZSBDYWxj +dXR0YSAoS29sa2F0YSlcPC9iXD5cPC9URFw+XDxURCBjbGFzcz0nQm9keVRleHQnXD4gQ +292ZXJzIHJlc2lkZW50cyBvZiBBc3NhbSwgTWFuaXB1ciwgTWVnaGFsYXlhLCBOYWdhbG +FuZCwgVHJpcHVyYSwgQmloYXIsIE9yaXNzYSwgV2VzdCBCZW5nYWwsIEFydW5hY2hhbCB +QcmFkZXNoLCBTaWtraW0sIE1pem9yYW0sIEpoYXJraGFuZCwgQW5kYW1hbiBhbmQgTmlj +b2JhciBJc2xhbmRzIFw8L1REXD5cPFREXD47Mz47Pj47Pjs7Pjs+Pjs+Pjs+ES4L3Lspg +y7Nq0zptOk6nJmcTfM=' &rdlZone = 1"); $agent->get("http://www.abc.com/CalendarDisp.aspx",":content_file" => +"cal.html" );
    Please suggest, esteemed monks!!
      Surely if that VIEWSTATE is a cookie you want to set it dynamically, and not with a fixed value? Thats probably what has expired..

      (Unless Im missing something, and WWW::Mechanize does cookie stuff behind the scenes that Im not aware of - did you check?)

      C.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://354860]
Approved by matija
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (3)
As of 2024-04-24 02:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found