URI::InvalidURIError(错误的 URI(不是 URI?):): [英] URI::InvalidURIError (bad URI(is not URI?): ):
问题描述
我正在尝试在 Rails 3 中实现 OAuth 提供程序.当我尝试授权客户端应用程序时,出现此错误.我正在使用 RESTful auth 插件和 pelles OAuth 插件.当我通过 Rails 控制台进行测试并收到此错误时,我以为我只需要对 URL 进行编码,但在浏览器中进行测试时出现相同的错误,因此我不确定是什么问题.
I am trying to implement an OAuth provider in Rails 3. When I try to authorize a client app I get this error. I am using the RESTful auth plugin and pelles OAuth-plugin. When I was testing via the Rails console and getting this error I thought that I simply needed to encode the URLs but I get the same error when testing in browser so I am not sure what is wrong.
推荐答案
我在使用 URI.split
时遇到了麻烦(返回此错误),我不知道这是否对您有帮助,但我将在这里发布一些警告给其他人也有这个错误:
I got into trouble with URI.split
(returning this error), I don't know if this helps you, but I will post here some warnings for also someone else having this error:
- 检查您的网址是否为空,并且它是有效的.
- 在
URI.parse
之前做URI.encode(url)
(避免特殊字符) - 对传递给
URI.parse
的字符串执行strip
(以避免前导和尾随空格).
- Check your url is not nil, and it's a valid one.
- Do
URI.encode(url)
beforeURI.parse
(to avoid special characters) - Do
strip
to the string you pass toURI.parse
(to avoid leading and trailing whitespaces).
多合一:
uri = URI.parse(URI.encode(url.strip))
相关资源:http://www.practicalguile.com/2007/09/15/rising-uriinvalidurierror-from-a-perfectly-valid-uri/
这篇关于URI::InvalidURIError(错误的 URI(不是 URI?):):的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!