Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

How to make LWP::Simple use a proxy?

by freak
on May 04, 2004 at 16:25 UTC ( #350408=perlquestion: print w/ replies, xml ) Need Help??
freak has asked for the wisdom of the Perl Monks concerning the following question:

How to make LWP::Simple to use a proxy (without LWP::UserAgent) OR what should the script be if LWP::Simple uses an LWP::UserAgent proxy ?

2004-05-05 Edit by jdporter: Changed title from 'Connections'

Comment on How to make LWP::Simple use a proxy?
Re: How to make LWP::Simple use a proxy?
by sgifford (Prior) on May 04, 2004 at 16:35 UTC
    This is in the documentation for LWP::Simple:
    The user agent created by this module will identify itself as "LWP::Simple/#.##" (where "#.##" is the libwww-perl version number) and will initialize its proxy defaults from the environment (by calling $ua->env_proxy).
    and for LWP::UserEgent:
    $ua->env_proxy
    Load proxy settings from *_proxy environment vari­ables. You might specify proxies like this (sh-syntax):
                 gopher_proxy=http://proxy.my.place/
                 wais_proxy=http://proxy.my.place/
                 no_proxy="localhost,my.domain"
                 export gopher_proxy wais_proxy no_proxy
    
    csh or tcsh users should use the "setenv" command to define these environment variables.

    On systems with case insensitive environment variables there exists a name clash between the CGI environment variables and the "HTTP_PROXY" environment variable normally picked up by env_proxy(). Because of this "HTTP_PROXY" is not honored for CGI scripts. The "CGI_HTTP_PROXY" environment variable can be used instead.

    So you should be able to simply set the appropriate environment variables.

Re: How to make LWP::Simple use a proxy?
by eXile (Priest) on May 04, 2004 at 16:37 UTC
    From the LWP::Simple manpage:
    The user agent created by this module will identify itself as "LWP::Simple/#.##" (where "#.##" is the libwww-perl version number) an +d will initialize its proxy defaults from the environment (by calling $ua->env_proxy).
    I think they mean the HTTP_PROXY environment-variable, so in your script you could set something like:
    $ENV{'HTTP_PROXY'}='http://proxy:3128/';
    before you create the user agent.
Re: How to make LWP::Simple use a proxy?
by Tomte (Priest) on May 04, 2004 at 16:37 UTC

    From the pod of LWP::Simple :

    The user agent created by this module will identify itself as "LWP::Simple/#.##" (where "#.##" is the libwww-perl version number) and will initialize its proxy defaults from the environment (by calling $ua->env_proxy).

    And accordingly looked up in the pod of LWP::UserAgent (emphasis again mine):

    Load proxy settings from *_proxy environment variables. You might specify proxies like this (sh-syntax):
    • gopher_proxy=http://proxy.my.place/
    • wais_proxy=http://proxy.my.place/
    • no_proxy="localhost,my.domain"
    • export gopher_proxy wais_proxy no_proxy
    csh or tcsh users should use the "setenv" command to define these environment variables.
    On systems with case insensitive environment variables there exists a name clash between the CGI environment variables and the "HTTP_PROXY" environment variable normally picked up by env_proxy(). Because of this "HTTP_PROXY" is not honored for CGI scripts. The "CGI_HTTP_PROXY" environment variable can be used instead.

    So just set up the environment accordingly, and LWP::Simple DWYM.

    regards,
    tomte


    An intellectual is someone whose mind watches itself.
    -- Albert Camus

      is there a difference between an LWP::Simple connection and an LWP::UserAgent connection ?

        Yes! LWP::Simple is easier to use ;-P

        Again from the pod:

        This module is meant for people who want a simplified view of the libwww-perl library. It should also be suitable for one-liners. If you need more control or access to the header fields in the requests sent and responses received, then you should use the full object-oriented interface provided by the "LWP::UserAgent" module.

        Meaning: It's a wrapper around LWP::UserAgent, simplifying it's use for simple cases...

        regards,
        tomte


        An intellectual is someone whose mind watches itself.
        -- Albert Camus

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2015-07-07 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (88 votes), past polls