JSON parse from a Remote URL which requires a username and password

自作多情 提交于 2019-12-09 11:03:37

问题


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:


try to password and user as additional option

 open("http://...", :http_basic_authentication=>[user, password])


来源:https://stackoverflow.com/questions/14520488/json-parse-from-a-remote-url-which-requires-a-username-and-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!