drbrain / net-http-persistent

Thread-safe persistent connections with Net::HTTP
http://seattlerb.rubyforge.org/net-http-persistent
339 stars 117 forks source link

support for basic auth in get request? #75

Closed maxstudener closed 4 years ago

maxstudener commented 8 years ago

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 8 years ago

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

drbrain commented 4 years ago

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