Sous proxy / Integrations / Ruby Net::HTTP

Proxy in Ruby Net::HTTP

In Net::HTTP the proxy goes in as positional arguments to start. Here is the order that gets the login to the proxy.

HTTPHTTPSLogin and passwordRotation and sticky
Ruby Net::HTTP · proxy
HOST
PORT
LOGIN
••••••
✓ IP: Germany, residentialRun

Why use a proxy in Ruby Net::HTTP

Net::HTTP is the HTTP client from Ruby's standard library. Proxy address, port, login and password are passed as the p_addr, p_port, p_user and p_pass arguments to Net::HTTP.new or Net::HTTP.start. The library doesn't support SOCKS.

What to pick

Take an HTTP proxy: Net::HTTP has no SOCKS. For data collection scripts rotation fits; for a session with one site, sticky.

Residential

from $0.6 / GB

Home ISP addresses. The main choice for accounts and protected sites.

VIP

$2 / GB

Hand-picked clean IPs, faster and more stable than regular residential.

Mobile

$4 / GB

Carrier IPs, for platforms that check addresses strictly.

Step-by-step setup

Button names are given exactly as they appear in Ruby Net::HTTP.

  1. Install nothing

    net/http is part of Ruby's standard library.

  2. Export the proxy

    Take an HTTP proxy in @SousProxyBot or the dashboard: host, port, login and password.

  3. Pass the proxy to start

    Argument order: site address, site port, then proxy address, proxy port, login and password. The proxy port is a number, no quotes.

  4. Enable SSL for https

    For https sites add use_ssl: true to the options. Net::HTTP opens the tunnel through the proxy itself.

  5. Run and check the IP

    Run ruby ip.rb. The console shows JSON with the proxy IP.

Code example

Put in your own HOST, PORT, LOGIN and PASSWORD from the bot or the dashboard.

ruby
require "net/http"
require "uri"

uri = URI("https://api.ipify.org?format=json")

Net::HTTP.start(uri.host, uri.port, "HOST", PORT, "LOGIN", "PASSWORD",
                use_ssl: true, open_timeout: 15, read_timeout: 15) do |http|
  response = http.get(uri.request_uri)
  puts response.body
end

Tested by running it

We ran this example ourselves: Ruby 3.3.6 · net-http 0.4.1. Real output below, IP hidden.

Terminal · ip.rb
$ ruby ip.rb
{"ip":"proxy IP"}

And this is the response when the password is wrong:

$ ruby ip.rb
…
	from /usr/lib/ruby/3.3.0/net/http.rb:1580:in `do_start'
	from /usr/lib/ruby/3.3.0/net/http.rb:1569:in `start'
	from /usr/lib/ruby/3.3.0/net/http.rb:1029:in `start'
	from ip.rb:6:in `<main>'

Common errors

The issues people most often bring to support.

!

407 Proxy Authentication RequiredLogin and password are in the wrong positions. Check the order: site address, site port, proxy address, proxy port, login, password.

!

Request goes out on your IPIf you pass only the site address and port, Net::HTTP takes the proxy from http_proxy or none at all. Pass the proxy explicitly.

!

SSL_connect ... wrong version numberuse_ssl: true is missing for an https site. Add it to the start options.

!

Net::OpenTimeoutThe proxy doesn't answer or the port is wrong. Test the line on /en/tools/proxy-checker/.

Need a proxy for Ruby Net::HTTP?

Residential, VIP and mobile IPs. HTTP and SOCKS5, pay per GB, 1 GB free to try.

FAQ

Can I take the proxy from an environment variable?

Yes, if you don't pass a proxy address Net::HTTP reads http_proxy by default. Explicit arguments are more reliable.

I need SOCKS5, what now?

Net::HTTP can't do it. Take an HTTP proxy from the same dashboard; it's enough for web requests.

How do I check rotation?

Run the script several times: with rotation the IP changes, with a sticky session it stays the same.