Install
Net::HTTP ships with Ruby. The gems are only for the Faraday and HTTParty examples.
gem install faraday httpartyRotating residential
The proxy arguments follow the target's host and port. Calling get on a Net::HTTP that has not been started opens a connection for that one request and closes it afterwards, so each pass of the loop goes out through a new tunnel and a new residential address.
require "json"
require "net/http"
PROXY_HOST = "resi.proxymonkey.io"
PROXY_PORT = 8000
uri = URI("https://httpbin.org/ip")
3.times do
http = Net::HTTP.new(uri.host, uri.port, PROXY_HOST, PROXY_PORT, "USER", "PASS")
http.use_ssl = true
http.open_timeout = 10
http.read_timeout = 30
puts JSON.parse(http.get(uri.path).body)["origin"]
endA static datacenter or ISP IP
Faraday takes the whole proxy URL in proxy:, credentials included, and the timeouts under request:. This one runs on your static datacenter IP. For an ISP order, use the host and port your dashboard lists for it.
require "faraday"
conn = Faraday.new(
url: "https://httpbin.org",
proxy: "http://USER:PASS@IP:PORT",
request: { open_timeout: 10, timeout: 30 },
)
%w[/ip /headers].each do |path|
res = conn.get(path)
puts res.status, res.body[0, 80]
endKeeping one identity
Inside one Net::HTTP.start block, requests share a single connection, and so a single tunnel and exit address. That is the simplest way to hold an address for a short multi-step flow on the rotating gateway. Net::HTTP keeps no cookies between requests; you carry Set-Cookie values yourself. For an address that holds across connections and runs, use a static IP or a residential sticky session; the session setting for your account is in the dashboard.