我读到HTTParty使用SSL if the port is set to 443,但我没有看到如何设置端口。有人可以为我澄清一下吗?
答案 0 :(得分:5)
检查规格:
目标URL应使用端口443.只需在目标URI末尾添加:443
即可使HTTParty使用SSL。
顺便说一下,HTTPS URL也会使用SSL。
示例:
http://foo.com => no SSL
https://foo.com => SSL
http://foo.com:443 => SSL
答案 1 :(得分:3)
除非端口为80且请求为HTTP:
,否则它实际上默认使用HTTPScontext "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