[英]undefined method `hostname' for “'http://www.google.com/”:String (NoMethodError)
我有以下代碼來獲取google.com
class Geocoder
def self.locate()
uri="http://www.google.com/"
puts Net::HTTP.get(uri)
end
但我面對的是犯罪者:
undefined method `hostname' for "'http://www.google.com/":String (NoMethodError)
我已經看過了 ,我的ruby版本是: ruby 2.2.1
你錯過了將字符串解析為URI ...這應該是什么樣子:
class Geocoder
def self.locate(address)
escaped_address = URI.escape(address)
uri = URI.parse(escaped_address)
puts Net::HTTP.get(uri)
end
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.