2012-10-29 17 views

Trả lời

4

Kiểm tra thông số kỹ thuật:

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

URL mục tiêu dự kiến ​​sẽ sử dụng cổng 443. Chỉ cần thêm :443 ở phần cuối của mục tiêu URI nên đủ để làm cho HTTParty sử dụng SSL.

Nhân tiện, URL HTTPS cũng sẽ sử dụng SSL.

Ví dụ:

http://foo.com  => no SSL 
https://foo.com => SSL 
http://foo.com:443 => SSL 
+0

+1. Tốt nhất để chỉ định 'https: //' trong URL, vì cổng sẽ mặc định là 443 tự động. –

+0

Đồng ý với @MarkThomas. Tốt để biết rằng bạn có thể sử dụng cả hai anyway. – robertodecurnex

3

Nó thực sự sử dụng HTTPS theo mặc định trừ cảng là 80 và yêu cầu là 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

Dưới đây là spec của tôi:

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 
Các vấn đề liên quan