It often happens that a proxy server is required to connect to the internet from your machine. This scenario usually occurs when internet is being accessed from behind the firewall. If you are accessing internet from any web browser then proxy and authentication parameters can be set in browser settings. However, if internet is being accessed from command prompt either by executing a command or through some scripts, it is required to set the proxy settings somehow.
To set the proxy server and authentication details, you can set the http_proxy environment variable. This environment variable can be set on windows and unix operating systems as below:
Setting http_proxy environment variable on windows
- Go to Start -> Control Panel -> System
- In System Properties panel, under Advanced Tab, click on Environment Variables.
- To add http_proxy as system variable, click on “New” under System variables, else click on “New” under User variables.
- In the New Variable panel, add the Variable name and Variable value as shown in the figure below:
- Update the username, password, Ip and Port values.
Setting http_proxy environment variable on unix
Update the username, password, Ip and Port values.
If any of the proxy details get change i.e. if server or port or username or password gets changed, http_proxy needs to be updated accordingly.
One instance where it is required to set http_proxy environment variable is when perl mechanize is used.
Hope the information presented here helped you in some way. Please let us know if there are better ways of doing the things…!!