JSON parse from a Remote URL which requires a user

2019-03-27 18:26发布

I have a url which points to a JSON output, however this URL requires a username and password through a standard apache pop up authentication box. I have tried to access this URL from my rails controller like the following:

result = JSON.parse(open("http://user:pass@myurl.com/json").read)

However it isn't working. I have the following at the top of my controller:

require 'open-uri'
require 'json'

I just get an error which says ArgumentError, userinfo not supported. [RFC3986]

1条回答
劳资没心,怎么记你
2楼-- · 2019-03-27 19:00

try to password and user as additional option

 open("http://...", :http_basic_authentication=>[user, password])
查看更多
登录 后发表回答