require 'net/http' require 'open-uri' def working_url?(url_str) url = URI.parse(url_str) Net::HTTP.start(url.host, url.port) do |http| http.head(url.request_uri).code == '200' end rescue false end
$url = "http://www.domain.com/demo.jpg"; $headers = @get_headers($url); if(strpos($headers[0],'404') === false) { echo "URL Exists"; } else { echo "URL Not Exists"; }
from urllib2 import urlopen code = urlopen("https://kipalog.com").code if code == 200: print "Exists!" # Or import urllib2 ret = urllib2.urlopen('https://kipalog.com') if ret.code == 200: print "Exists!"
#!/bin/bash http_code=$(curl -I -s -o /dev/null -w "%{http_code}" "https://kipalog.com/") if [ "$http_code" == "200" ]; then echo "Exist!!!" fi
$url = "http://www.domain.com/demo.jpg"; $curl = curl_init($url); curl_setopt($curl, CURLOPT_NOBODY, true); $result = curl_exec($curl); if ($result !== false) { $statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE); if ($statusCode == 404) { echo "URL Not Exists" } else { echo "URL Exists"; } } else { echo "URL not Exists"; }
Оригинал: “https://dev.to/dereknguyen269/how-to-check-url-is-working-or-not-in-programing-languages-2k9m”