Being completely flustered, I once again turn to the Monastery for help:

I am using LWP::UserAgent to post to a couple of secure servers. When I post to the test server, everything works just fine. When I post to the production server, the script dies with the following error:

Can't call method "request" on an undefined value at /usr/lib/perl5/si +te_perl/5.6.0/LWP/UserAgent.pm line 362.

(It appears that the useragent object is somehow disappearing.) The only difference between the two runs is the URL. I've tried running the same script from another server with the same versions of LWP, HTTP::Request, etc., and both passes seem to work right. The code I am running is very simple:

#!/usr/bin/perl -w use strict; use CGI::Carp qw( fatalsToBrowser ); require LWP::UserAgent; use HTTP::Request; use HTTP::Headers; print "Content-type: text/html\n\n"; my $ua = new LWP::UserAgent; my $content = 'Content'; my $URL = 'https://some.address.here'; my $headers = HTTP::Headers->new( MIME_version => '1.0', Content_type => 'application/PTI9', Content_length => length($content), Content_transfer_encoding => 'text', Request_number => 1, Document_type => 'Request', ); print <<"EOH"; <html> <head><title>LWP Test</title></head> <body> <h2>Request</h2> <pre> EOH my $request = HTTP::Request->new(POST => $URL, $headers, $content); print $request->as_string(); print <<"EOH"; </pre> <h2>Response</h2> <pre> EOH my $response = $ua->request($request); if ($response->is_success) { print $response->content; } else { print $response->error_as_HTML; } print <<"EOH"; </pre><h2>Completed</h2> </body></html> EOH exit;

and here are the results of an LWP::Debug trace from the failed attempt(s):

LWP::UserAgent::new: () LWP::UserAgent::request: () LWP::UserAgent::send_request: POST https://some.adddress.here LWP::UserAgent::_need_proxy: Not proxied LWP::Protocol::http::request: () Can't call method "request" on an undefined value at /usr/lib/perl5/si +te_perl/5.6.0/LWP/UserAgent.pm line 362.

I've searched the Monastery and Google, but haven't found a solution. I would appreciate any help my fellow monks can give.


Impossible Robot

In reply to LWP dies calling request method by impossiblerobot

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.