0
我正在進行HTTPS調用,調試如下。 open_uri正常工作:open-uri工作但net :: http,爲什麼?
irb(main):053:0* r=OpenURI::open_uri("https://192.168.8.123/api/1.0/appliance-management/components/component/status", opts)
=> #<StringIO:0x007fc6e4a8ee38 @base_uri=#<URI::HTTPS https://192.168.8.123/api/1.0/appliance-management/components/component/status>, @meta={"cache-control"=>"private", "expires"=>"Thu, 01 Jan 1970 00:00:00 GMT", "set-cookie"=>"JSESSIONID=B117FD42DA5509EBF99627C08332F249; Path=/; Secure; HttpOnly", "content-type"=>"application/json", "transfer-encoding"=>"chunked", "date"=>"Fri, 15 Apr 2016 14:16:08 GMT", "server"=>""}, @metas={"cache-control"=>["private"], "expires"=>["Thu, 01 Jan 1970 00:00:00 GMT"], "set-cookie"=>["JSESSIONID=B117FD42DA5509EBF99627C08332F249; Path=/; Secure; HttpOnly"], "content-type"=>["application/json"], "transfer-encoding"=>["chunked"], "date"=>["Fri, 15 Apr 2016 14:16:08 GMT"], "server"=>[""]}, @status=["200", "OK"]>
但網:: HTTP總是得到ReadTimeout錯誤:
irb(main):096:0* http = Net::HTTP.new('192.168.8.123', 443)
=> #<Net::HTTP 192.168.8.123:443 open=false>
irb(main):097:0> http.use_ssl = true
=> true
irb(main):099:0> http.verify_mode=OpenSSL::SSL::VERIFY_NONE
=> 0
irb(main):102:0* req = Net::HTTP::Get.new("/api/1.0/appliance-management/components/component/status", {})
=> #<Net::HTTP::Get GET>
irb(main):104:0* req.basic_auth('admin', 'default')
=> ["Basic YWRtaW46ZGVmYXVsdA=="]
irb(main):106:0* http.request(req)
Net::ReadTimeout: Net::ReadTimeout
from /opt/ruby/2.2.0/lib/ruby/2.2.0/net/protocol.rb:158:in `rescue in rbuf_fill'
這有什麼錯我的Net :: HTTP代碼?
可以確認192.168.8.123在端口443到達? 'telnet 192.168.8.123 443' 應迴應 '連接到192.168.8.123。 轉義字符是'^]' 如果是這樣 –
正如你所看到的,open_uri的工作原理。 – TieDad