簡體   English   中英

'http://www.google.com/":String(NoMethodError)的未定義方法`hostname'

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM