少於 1 分鐘閱讀

#加入function

def remote_file_exists?(url)  
  url = URI.parse(url)  
  Net::HTTP.start(url.host, url.port) do |http|  
    return http.head(url.request_uri).code == "200"  
  end  
end 

測試

puts remote_file_exists? 'http://www.www.www'     # => false  
puts remote_file_exists? 'http://www.google.com/'  # => true  

更新時間:

留言