这篇文章上次修改于 253 天前,可能其部分内容已经发生变化,如有疑问可询问作者。
有些小伙伴的服务器检测图片状态很慢,所以写了一份利用
cloudflare workers
获取http status code
的代码
可用于Hidove图床图片状态检测接口
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
let url = new URL(request.url).searchParams.get("url");
if(!url)
return new Response("url异常");
const response = await fetch(url);
return new Response(response.status);
}
PHP版
if (!isset($_GET['url'])) {
return '请输入正确的url';
}
$url = isset($_GET['url']) ? $_GET['url'] : '';
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_REFERER, isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : 'https://www.gov.cn');
curl_setopt($curl, CURLOPT_NOBODY, true);
#关闭ssl
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
#在尝试连接时等待的秒数。设置为 0,则无限等待。
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 5);
#允许 cURL 函数执行的最长秒数。
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_exec($curl); //开始执行啦~
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl); //用完记得关掉他
echo $code;
example:https://status-code.abcyun.workers.dev/?url=https://www.hidove.cn
php那个版本那
没有php版