【发布时间】:2021-05-03 06:17:27
【问题描述】:
我有一个 Ruby 代码:
require 'net/http'
url = "https://stackoverflow.com/questions/65798852/how-do-i-set-an-electron-variable-at-compile-time"
response = Net::HTTP.get_response(url, '/')
会产生错误:
getaddrinfo: nodename nor servname provided, or not known (SocketError)
和
Failed to open TCP connection to https://stackoverflow.com/questions/65798852/how-do-i-set-an-electron-variable-at-compile-time:80 (getaddrinfo: nodename nor servname provided, or not known) (SocketError)
但它与 uri 完美配合:
require 'net/http'
url = "https://stackoverflow.com/questions/65798852/how-do-i-set-an-electron-variable-at-compile-time"
uri = URI(url)
response = Net::HTTP.get_response(uri)
那么,谁能解释一下有什么区别,为什么会这样,以及 URI 有什么特别之处?
【问题讨论】:
-
Documentation 提到
The target can either be specified as (uri), or as (host, path, port = 80)所以第一次调用成功应该是Net::HTTP.get_response('stackoverflow.com', '/questions/65798852/how-do-i-set-an-electron-variable-at-compile-time')