【发布时间】:2012-10-29 15:42:56
【问题描述】:
我读到 HTTParty 使用 SSL if the port is set to 443,但我不知道如何设置端口。有人可以帮我澄清一下吗?
【问题讨论】:
我读到 HTTParty 使用 SSL if the port is set to 443,但我不知道如何设置端口。有人可以帮我澄清一下吗?
【问题讨论】:
检查规格:
目标 URL 应使用端口 443。只需在目标 URI 末尾添加 :443 就足以使 HTTParty 使用 SSL。
顺便说一句,HTTPS URL 也将使用 SSL。
例子:
http://foo.com => no SSL
https://foo.com => SSL
http://foo.com:443 => SSL
【讨论】:
https://,因为端口会自动默认为 443。
它实际上默认使用HTTPS,除非端口是80并且请求是HTTP:
context "using port 80" do
let(:uri) { URI 'http://foobar.com' }
it { should_not use_ssl }
end
context "using port 443 for ssl" do
let(:uri) { URI 'https://api.foo.com/v1:443' }
it { should use_ssl }
end
context "https scheme with default port" do
it { should use_ssl }
end
context "https scheme with non-standard port" do
let(:uri) { URI 'https://foobar.com:123456' }
it { should use_ssl }
end
https://github.com/jnunemaker/httparty/blob/master/spec/httparty/connection_adapter_spec.rb
这是我的规格:
describe Foo do
it 'is https' do
adapter = HTTParty::ConnectionAdapter.new(URI(subject.base_uri))
expect(adapter.connection.use_ssl?).to eq(true)
end
end
【讨论】: