from my RoR controller, I'm trying to send http requests that need a username and password.
I tried this
url = 'http://192.168.122.198 ...'
uri = URI.parse(url)
request = Net::HTTP::Get.new(uri.path)
request['Accept'] = 'application/json'
request.body = {'credentials' => {'username' => 'admin', 'password' => 'admin'}}
response = Net::HTTP.get(uri)
but I'm getting this error
Error 401 Unauthorized
Any idea how can I pass the username and password in my request?
Try following
uri = URI.parse("http://192.168.122.198")
http = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Get.new(uri.request_uri)
request.basic_auth("admin", "admin")
response = http.request(request)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With