I am using ruby 1.9.3 and trying to use open-uri
to get the url and try to send using Net:HTTP
I am trying to use proxy authentication for both:
Trying to execute a POST
request using net/http
:
require 'net/http' require 'open-uri' http = Net::HTTP.new("google.com", 80) headers = { 'User-Agent' => 'Ruby 193'} resp, data = http.post("/", "name1=value1&name2=value2", headers) puts data
And for open-uri
, which I cannot do POST
, I use:
data = open("http://google.com/","User-Agent"=> "Ruby 193").read
How do I change them to use a proxy with HTTP authentication
I tried (for open-uri)
data = open("http://google.com/","User-Agent"=> "Ruby 193", :proxy_http_basic_authentication => ["http://proxy.com:8000/", "proxy-user", "proxy-password"]).read
However, all I get is OpenURI::HTTPError: 407 Proxy Authentication Required
. I checked everything and it works in the browser with the same authentication and proxy settings, but I cannot get Ruby to do this.
How do I change the code above to properly add HTTP authentication? Has anyone gone through this atrocity?
source share