gpt4 book ai didi

ruby - HTTP 请求错误 : name or service not known

转载 作者:太空宇宙 更新时间:2023-11-03 16:04:12 25 4
gpt4 key购买 nike

我正在尝试通过 Ruby 发出 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 将自动使用环境变量中指定的 HTTP 代理。

EXPORT http_proxy=http://foo.bar:8080/
ruby your_http_script.rb

关于ruby - HTTP 请求错误 : name or service not known,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17708218/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com