我正在使用登录名和密码进行https身份验证,根据RFC,URI应如下所示:
https://username:password@example.com:8042/
但是,当登录是电子邮件时,@
符号被解释为主机分隔符:
https://username@example.com:password@example.com:8042/
正确的 URI 应该是什么样子的?
[编辑] 一些背景:我正在使用 PivotalTracker 身份验证令牌
检索require 'net/http'
require 'net/https'
require 'open-uri'
def validate_with_credentials
doc = Nokogiri::XML(open(authentication_uri, :http_basic_authentication => [email, password]))
end
def authentication_uri
URI('https://www.pivotaltracker.com/services/v4/me')
end
这有效,但我想在我的功能测试中存根网址,我正在使用 FakeWeb gem:
FakeWeb.register_uri(:get, 'https://correct_email@example.com:correct_password@www.pivotaltracker.com/services/v4/me',
:body => File.read(File.join(Rails.root, 'spec', 'fixtures', 'pivotal_tracker', 'responses', 'authorization_success.xml')),
:status => ['200', 'OK'])
这里的问题是 uri 不应该有双@
,我得到异常:
URI::InvalidURIError:方案 https 不接受注册表部分: correct_email@example.com:correct_password@www.pivotaltracker.com(或 主机名不好?
我不得不使用编码并将@
替换为%40
。由拉维·帕雷克提供