I have the following code to get google.com
class Geocoder
def self.locate()
uri="http://www.google.com/"
puts Net::HTTP.get(uri)
end
but i faced with the erorr:
undefined method `hostname' for "'http://www.google.com/":String (NoMethodError)
I have already seen this , and my ruby version is: ruby 2.2.1
You're missing parsing the string into a URI... Here is what it should look like:
class Geocoder
def self.locate(address)
escaped_address = URI.escape(address)
uri = URI.parse(escaped_address)
puts Net::HTTP.get(uri)
end
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.