drbrain/net-http-persistent

support for basic auth in get request?

Closed this issue · 2 comments

Not sure why this isn't working or maybe I am holding something wrong. My server is not getting the http basic auth creds, any idea?

http = Net::HTTP::Persistent.new
uri = URI( URI.escape( SCHEMA + '://' + USERNAME + ':' + PASS + '@' + DOMAIN + URL_PATH + "?" + params.map { |k, v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&') ))
http.read_timeout = 30
http.request uri
BoGs commented

Just build the request and attach the basic_auth to it as in this example.

You could do http.request <your built request>

http://ruby-doc.org/stdlib-2.3.1/libdoc/net/http/rdoc/Net/HTTP.html#class-Net::HTTP-label-Basic+Authentication

Yes, or use mechanize wraps net-http-persistent and supports specifying which passwords belong to which URLs and realms.