我試圖通過Ruby發出HTTP請求。當運行下面的代碼:HTTP請求錯誤:名稱或服務未知
require "net/http"
require "uri"
uri = URI.parse("http://google.com/")
# Will print response.body
Net::HTTP.get_print(uri)
我得到以下錯誤:
SocketError: initialize: name or service not known
from org/jruby/ext/socket/RubyTCPSocket.java:129:in `initialize'
from org/jruby/RubyIO.java:1179:in `open'
from c:/jruby-1.7.3/lib/ruby/1.9/net/http.rb:762:in `connect'
from org/jruby/ext/timeout/Timeout.java:105:in `timeout'
from c:/jruby-1.7.3/lib/ruby/1.9/net/http.rb:762:in `connect'
from c:/jruby-1.7.3/lib/ruby/1.9/net/http.rb:755:in `do_start'
from c:/jruby-1.7.3/lib/ruby/1.9/net/http.rb:744:in `start'
from c:/jruby-1.7.3/lib/ruby/1.9/net/http.rb:454:in `get_response'
from c:/jruby-1.7.3/lib/ruby/1.9/net/http.rb:412:in `get_print'
from (irb):29:in `evaluate'
from org/jruby/RubyKernel.java:1066:in `eval'
from org/jruby/RubyKernel.java:1409:in `loop'
from org/jruby/RubyKernel.java:1174:in `catch'
from org/jruby/RubyKernel.java:1174:in `catch'
from c:/jruby-1.7.3/bin/irb:13:in `(root)'
這可能是代理相關的,但我不知道。我該如何解決這個問題?
您的機器是否連接到互聯網?你有沒有嘗試過另一個Ruby? –
「這可能與代理有關」,所以請告訴我們,您是否通過代理運行? –
是的,我。我嘗試過使用httpclient庫做同樣事情的其他方式,在這種情況下,它給了我一個arg錯誤,指出代理:8080無效。我嘗試用手動代理設置覆蓋它,但它總是返回相同的錯誤消息。 – user472875