I can easily do it on the command line using curl:
curl --digest -u "user:password" [url]
But I'm trying to use Ruby Net :: HTTP. Is there a way that I can provide my username and password when trying to use Net :: HTTP for the GET API?
I tried the basic_auth method, but it does not work.
here is my code snippet
basic auth
uri = URI("https://www.commcarehq.org/a/chanderi/api/v0.4/form/?xmlns=http://openrosa.org/formdesigner/C3B60561-F631-4D4C-8611-10E975EF8B44") res = Net::HTTP.start(uri.hostname, uri.port) {|http| req = Net::HTTP::Get.new(uri) req.basic_auth 'myusername', 'mypassword' http.request(req) } puts res.body
for network :: http :: digestauth
digest_auth = Net::HTTP::DigestAuth.new uri = URI.parse 'http://localhost:8000/' uri.user = CGI.escape(' username@mail.com ') uri.password = 'password' h = Net::HTTP.new uri.host, uri.port req = Net::HTTP::Get.new uri.request_uri res = h.request req
Net :: HTTPBadResponse: invalid status bar: ""
I follow http://docs.seattlerb.org/net-http-digest_auth/Net/HTTP/DigestAuth.html
source share