Ruby Proxy Configuration Examples
This article describes options for configuring the Proxy Host with Basic Authentication in the Ruby scripting language for an HTTP client.
For Ruby HTTP clients, if you are using IP authentication, you can leave out the username:password
parts.
options = {proxy: 'http://PROXYHOST:PORT', proxyuserpwd: 'USERNAME:PASSWORD'} req = Typhoeus::Request.new(url, options) req.run
Below is a code example for a REST API call behind a proxy:
require "uri" require 'net/http' proxy_host = '<proxy addr>' proxy_port = '<proxy_port>' proxy_user = '<username>' proxy_pass = '<password>' uri = URI.parse("https://saucelabs.com:80/rest/v1/users/<username>") proxy = Net::HTTP::Proxy(proxy_host, proxy_port, proxy_user, proxy_pass) req = Net::HTTP::Get.new(uri.path) req.basic_auth(<sauce_username>,<sauce_password>) result = proxy.start(uri.host,uri.port) do |http| http.request(req) end puts result.body