Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Test For JPEG Image Over HTTP
neilc
8/17/2006 8:13:00 AM
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/imag...
)
end
--
Posted via
http://www.ruby-...
.
1 Answer
Alex Young
8/17/2006 8:21:00 AM
0
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/imag...
)
>
> 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
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Test For JPEG Image Over HTTP
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password