鞋子 Rb 主机名未知:sub.localhost:3000



我正在使用鞋子的GUI构建器,当我向本地Rails服务器发出简单的HTTP请求时,我收到以下错误

所以当我提出请求时

res = Net::HTTP.get(URI.parse("http://sub.localhost:3000"))

我收到错误:

Hostname not known: sub.localhost
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/resolv-replace.rb:12:in `rescue in getaddress'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/resolv-replace.rb:9:in `getaddress'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/resolv-replace.rb:23:in `initialize'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:879:in `open'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:879:in `block in connect'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/timeout.rb:73:in `timeout'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:878:in `connect'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:863:in `do_start'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:852:in `start'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:1375:in `request'
shoes.rb:24:in `request'
shoes.rb:63:in `block (3 levels) in <main>'
-e:1:in `call'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/resolv-replace.rb:12:in `rescue in getaddress'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/resolv-replace.rb:9:in `getaddress'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/resolv-replace.rb:23:in `initialize'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:879:in `open'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:879:in `block in connect'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/timeout.rb:73:in `timeout'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:878:in `connect'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:863:in `do_start'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:852:in `start'
/Applications/Shoes.app/Contents/MacOS/lib/ruby/2.2.0/net/http.rb:1375:in `request'
shoes.rb:24:in `request'
shoes.rb:63:in `block (3 levels) in <main>'
-e:1:in `call'

我的主机文件有127.0.0.1 sub.localhost,我可以到达该地址并针对它提出请求没有问题,只是不在鞋子项目中。

我按照这个问题的建议ex 123.12.12.1绑定了我的本地 IP 地址,但得到同样的错误Hostname not known: sub.123.12.12.1

这说要删除鞋子项目中的行resolv-replace.rb:9:in,但我得到同样的错误Hostname not known: sub.123.12.12.1

我在电脑上

使用自定义 DNS 解析器来确保 Ruby 查看hosts文件:

require 'resolv-replace'
hosts_resolver = Resolv::Hosts.new('custom_hosts')
dns_resolver = Resolv::DNS.new
Resolv::DefaultResolver.replace_resolvers([hosts_resolver, dns_resolver])
require "net/http"
require "uri"
res = Net::HTTP.get(URI.parse("http://sub.localhost:3000"))

现在,Net::HTTP将使用首先检查hosts并成功解析自定义域的自定义解析程序。

相关内容

  • 没有找到相关文章

最新更新