Hi
I would like to test for the existence of a .jpg image on a remote
server over HTTP.
I have tried 2 different methods but they are not what I need.
Method 1:
require 'open-uri'
if open('http://example.net/path/to/image.jpg')
end
···
--
Posted via http://www.ruby-forum.com/.
Neil Charlton wrote:
Hi
I would like to test for the existence of a .jpg image on a remote server over HTTP.
I have tried 2 different methods but they are not what I need.
Method 1:
require 'open-uri'
if open('http://example.net/path/to/image.jpg'\)
end
require 'net/http'
# Strict existence
def url_exists?(path)
u = URI.parse(path)
h = Net::HTTP.new(u.host, u.port)
r = h.head(u.path)
return Net::HTTPOK === r
end
# Lack of non-existence
def url_found?(path)
u = URI.parse(path)
h = Net::HTTP.new(u.host, u.port)
r = h.head(u.path)
return !(Net::HTTPNotFound === r)
end
···
--
Alex