Guides
How to send requests through a proxy in Ruby (Net::HTTP)
A request through an HTTP proxy with a login and password in Ruby using Net::HTTP.
What you need
The proxy is issued in the format host:port:login:password. Replace HOST, PORT, LOGIN and PASSWORD with your own values. The net/http library ships with standard Ruby; nothing needs to be installed.
Example
require "net/http"
require "uri"
uri = URI("https://api.ipify.org")
# The last four arguments: the proxy's address, port, login and password.
# The login and password are passed separately, no need to encode them
http = Net::HTTP.new(uri.host, uri.port, "HOST", "PORT", "LOGIN", "PASSWORD")
# HTTPS site: we enable encryption for the site itself, while the proxy works over HTTP
http.use_ssl = true
http.open_timeout = 15
http.read_timeout = 30
response = http.get(uri.request_uri)
# The service returns the address the request came from
puts response.bodyIf SOCKS5
Net::HTTP works only with HTTP proxies; SOCKS is not mentioned in its documentation. Use the proxy's HTTP port.
Common errors
- Response 407 Proxy Authentication Required: the login or password is wrong. Check the order in the issued host:port:login:password.
- Net::OpenTimeout or Net::ReadTimeout: check HOST and PORT, whether the SOCKS5 port was put into HTTP mode, and increase the timeouts.
- Special characters in the password: when the login and password are passed as separate arguments, nothing needs encoding. If you build the proxy address as a string, encode the values with URI.encode_www_form_component.
- The https:// scheme for the proxy: the issued proxy works over HTTP, so the proxy is given simply as an address and port; use_ssl refers to the site, not the proxy.
- If p_addr is not specified, Net::HTTP takes the proxy from the http_proxy environment variable. Set the proxy address explicitly, as in the example.
Sources
Checked against the official documentation: October 2026. Program interfaces change: if item names differ, follow the documentation.
All guides are collected on the Guides page.
Find a proxy in the chat