繁体   English   中英

cURL / GuzzleHTTP直接下载链接的检查状态代码

[英]cURL/GuzzleHTTP check status code of direct download link

我有这样的从谷歌驱动器直接下载链接

https://doc-08-48-docs.googleusercontent.com/docs/securesc/xxxx?e=download

从给定的下载链接,我想检查给定的链接是否仍然有效,我如何使用cURLGuzzleHTTP实现它?

我找到了解决方案,这是我用来验证直接下载链接的方法

$url = "https://doc-08-48-docs.googleusercontent.com/docs/securesc/xxxxxx?e=download";
$ch = curl_init();
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'GET' );
curl_setopt( $ch, CURLOPT_HEADER, 1 );
curl_setopt( $ch, CURLOPT_NOBODY, true );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_exec( $ch );
$statusCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);echo $statusCode;

希望它能帮助其他人,加油!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM