Thursday, May 5, 2011

Using proxy with open-uri

If you need to open web page using open-uri's open() method through a proxy you can do something like this

open('www.example.com', :proxy=>'http://#{proxy_ip}:#{proxy_port}').readlines

If you need proxy authentication you can do something like this

open('www.example.com', :proxy_http_basic_authentication => ['http://#{proxy_ip}:#proxy_port}', 'proxyuser', 'proxypass'] ).readlines

replace proxyuser and proxypass with user actual proxy username and password.

No comments:

Post a Comment