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

Hi,

In the following snippet of code, I have a LWP useragent behind a proxy making a request, where the content body is saved to a file.

$ua = new LWP::UserAgent( keep_alive => 1 ); $ua->proxy(['http', 'https'], $proxy); $request = HTTP::Request->new('GET', 'http://www.google.com'); $response = $ua->request($request, '/root/content_file');

In doing so, the content_file is empty after executing the code, and the response object contains a '_content' member (suggesting to me that the content did not get transferred over to the file).


Has anyone else run into this problem?

Thank you!

Replies are listed 'Best First'.
Re: Empty content_file for LWP behind a proxy
by Anonymous Monk on Jun 03, 2014 at 00:31 UTC

    In doing so, the content_file is empty after executing the code,

    Well, that code isn't supposed to create a file

    Switch to WWW::Mechanize, its less typing/friendlier interface to LWP

    $mech->get( $uri, ':content_file' => $tempfile );
Re: Empty content_file for LWP behind a proxy
by taint (Chaplain) on Jun 02, 2014 at 21:57 UTC
    Greetings, jnwu.

    A couple of things come to mind;
    Did you

    use warnings;
    If so, was any interesting output generated?

    Is this run via the web -- as a web based script, or the likes?
    If so, what do your web logs say? Any informational output that might be of help?

    Best wishes.

    --Chris

    ¡λɐp ʇɑəɹ⅁ ɐ əʌɐɥ puɐ ʻꜱdləɥ ꜱᴉɥʇ ədoH