Brandon Brandon - 8 months ago 57
Ruby Question

Ruby Post Request with Basic Auth and Multiple Params

I'm having a ridiculously hard time doing something presumably simple...

I am trying to run a simple POST request in ruby. I've looked at curb, typhoeus, rest-client, etc... The post request has basic auth (via api key) and two params...

I have the command written out in curl form below, which works perfectly.

curl -X POST -u any_string:abc123 -d var1="help" -d var2="me"

Can anyone help me translate this into ruby? I don't mind using typhoeus, curb, etc... as long as it works...


I've use this tool before with some success.

Your curl statement generates this Ruby code.

require 'net/http'
require 'uri'

uri = URI.parse("")
request =
request.basic_auth("any_string", "abc123")
  "var1" => "help",
  "var2" => "me",

response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|

# response.code
# response.body

There are about a million different HTTP request libraries in Ruby but sometimes its just simple to write it in Net HTTP (Net HTTP is included in the Ruby Standard Library).