spacer
spacer

Perl and Proxies

Network Proxy Configuration

Depending on the network configuration it may be necessary to configure FTP or HTTP proxies to connect to remote services. Most Perl modules which make network connections check the the environment for variables which define how to connect to a proxy.

HTTP Proxy

On UNIX and UNIX-like systems the environment variables can be set in the shell.

  1. C-shell (csh or tcsh):
    1. Without authentication:
      setenv http_proxy 'http://proxy.example.org:8080'
      setenv HTTP_proxy 'http://proxy.example.org:8080'
    2. With authentication:
      setenv http_proxy 'http://username:password@proxy.example.org:8080'
      setenv HTTP_proxy 'http://proxy.example.org:8080'
      setenv HTTP_proxy_user 'username'
      setenv HTTP_proxy_pass 'password'
  2. Bourne shell (sh or bash):
    1. Without authentication:
      http_proxy='http://proxy.example.org:8080'
      HTTP_proxy='http://proxy.example.org:8080'
      export http_proxy HTTP_proxy
    2. With authentication:
      http_proxy='http://username:password@proxy.example.org:8080'
      HTTP_proxy='http://proxy.example.org:8080'
      HTTP_proxy_user='username'
      HTTP_proxy_pass='password'
      export http_proxy HTTP_proxy HTTP_proxy_user HTTP_proxy_pass

On MS Windows the proxy configuration is obtained from the network configuration, and so should not need to be set on a per application basis.

The environment variables can also be set from within a Perl program, for example:

$ENV{'http_proxy'} = 'http://proxy.example.org:8080';
$ENV{'HTTP_proxy'} = 'http://proxy.example.org:8080';

In many cases the proxy details can also be passed to the Perl module directly. Since this is module specific, see the module documentation for details.


Up Perl Contents Contents
 
tutorials/06_programming/perl/proxy.txt · Last modified: 2010/02/14 17:59 by hpm
spacer
spacer