method
Proxy
v1_9_3_125 -
Show latest stable
- Class:
Net::HTTP
Proxy(p_addr, p_port = nil, p_user = nil, p_pass = nil)public
Creates an HTTP proxy class which behaves like Net::HTTP, but performs all access via the specified proxy.
The arguments are the DNS name or IP address of the proxy host, the port to use to access the proxy, and a username and password if authorization is required to use the proxy.
You can replace any use of the Net::HTTP class with use of the proxy class created.
If p_addr is nil, this method returns self (a Net::HTTP object).
# Example proxy_class = Net::HTTP::Proxy('proxy.example.com', 8080) proxy_class.start('www.ruby-lang.org') {|http| # connecting proxy.foo.org:8080 }
You may use them to work with authorization-enabled proxies:
proxy_host = 'your.proxy.example' proxy_port = 8080 proxy_user = 'user' proxy_pass = 'pass' proxy = Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass) proxy.start('www.example.com') { |http| # always connect to your.proxy.example:8080 using specified username # and password }
Note that net/http does not use the HTTP_PROXY environment variable. If you want to use a proxy, you must set it explicitly.