Open-URI and Basic Authentication

OpenURI is a really useful part of the Ruby standard library. I never used it with basic authentication but I thought than specify credential in URL was enough. I was wrong. It returns an error:

ArgumentError: userinfo not supported. [RFC3986]

The right way to use auth params is a bit hidden in the documentation page. You can find it in the OpenRead open method as option.

open("http://www.your-website.net", 
http_basic_authentication: ["user", "password"])

Source:

  • Pawel

    Thanks, this is very useful.