6

我读到 HTTParty如果端口设置为 443 则使用 SSL ,但我看不到如何设置端口。有人可以为我澄清一下吗?

4

2 回答 2

5

检查规格:

https://github.com/jnunemaker/httparty/blob/82a90c1b93b076f9d2d7410123c2b5d609401a1f/spec/httparty/request_spec.rb#L41

目标 URL 应使用端口 443。只需:443在目标 URI 的末尾添加 就足以使 HTTParty 使用 SSL。

顺便说一句,HTTPS URL 也将使用 SSL。

例子:

http://foo.com     => no SSL
https://foo.com    => SSL
http://foo.com:443 => SSL
于 2012-10-29T16:06:33.403 回答
3

它实际上默认使用 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
于 2014-03-25T02:33:16.560 回答