How to Set Up Proxies in Ruby (Net::HTTP)
Route Ruby (Net::HTTP) traffic through an authenticated proxy in a few lines. Copy the code below and swap in your credentials.
Quick answer
Set the proxy in the format host, port, user, pass positional args and send your Ruby (Net::HTTP) request through it. Full code below.
Ruby (Net::HTTP) proxy example
require "net/http"
require "uri"
uri = URI("https://httpbin.org/ip")
proxy = Net::HTTP.new(uri.host, uri.port,
"host", port, "user", "pass")
proxy.use_ssl = true
response = proxy.get(uri.request_uri)
puts response.bodyNet::HTTP.new accepts the proxy host, port, user, and password as trailing positional arguments, so authenticated endpoints need no extra gems. Remember to set use_ssl = true before the request when the target is HTTPS, otherwise the tunnel is never negotiated. For heavier scraping many Ruby teams prefer the httparty or faraday gems, both of which accept a proxy option hash pointed at a rotating gateway.
Rotating proxies
Ruby (Net::HTTP) works cleanly with rotating backconnect endpoints — point it at a single gateway host and the provider rotates the exit IP for you.
Best proxies to use with Ruby (Net::HTTP)
Cheapest-Proxies.com EDITOR'S CHOICE
4.9Best overall value across every proxy type and use case · flexible pay-as-you-go plans
Visit Cheapest-Proxies.comBright Data
4.6Enterprise-grade proxy and web data platform · from ~$8-9/GB (residential, volume-dependent)
Read Bright Data reviewOxylabs
4.6Premium enterprise proxies and scraper APIs · from ~$8/GB (residential, volume-dependent)
Read Oxylabs reviewSmartproxy
4.5User-friendly proxies with excellent price-to-performance · from ~$3.50-7/GB (residential)
Read Smartproxy reviewOur #1 pick is a sponsored partner. Remaining providers are ranked editorially by rating and value.
Frequently Asked Questions
How do I add a proxy in Ruby (Net::HTTP)?
Supply the proxy as host, port, user, pass positional args and pass it to Ruby (Net::HTTP) as shown in the code above.
Can Ruby (Net::HTTP) rotate proxies automatically?
Yes — point it at a rotating backconnect endpoint and the provider rotates IPs for you.
Does Ruby (Net::HTTP) support authenticated proxies?
Yes. Provide the username and password (as a URL or separate fields) and Ruby (Net::HTTP) handles the auth handshake.
What proxies work best with Ruby (Net::HTTP)?
Residential or rotating proxies from a reliable provider give the best success rate for Ruby projects.
Related Guides
Best proxies for Ruby (Net::HTTP)
Best value in our comparison, with competitive pricing across every proxy type — see the current deal.
Visit Cheapest-Proxies.com