我正在使用多卷曲从远程站点获取数据.我的剧本就像
foreach ($urls as $i => $url) { $ch[$i] = curl_init($url['url']); curl_setopt($ch[$i],CURLOPT_TIMEOUT,0); curl_setopt($ch[$i],CURLOPT_RETURNTRANSFER,1); curl_setopt($ch[$i],CURLOPT_CONNECTTIMEOUT,CURLOPT_SSL_VERIFYPEER,false); curl_multi_add_handle($multiCurlHandler,$ch[$i]); }@H_404_3@它返回我403禁止作为回应. @H_404_3@提前感谢您的建议和意见.
只需尝试为用户代理添加两行,然后查看它是否有效.
某些服务器不接受来自脚本的请求,这取决于用户代理.
原文链接:https://www.f2er.com/php/135438.html某些服务器不接受来自脚本的请求,这取决于用户代理.
// line 1 $agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)'; foreach ($urls as $i => $url) { $ch[$i] = curl_init($url['url']); curl_setopt($ch[$i],0); curl_setopt($ch[$i],1); curl_setopt($ch[$i],0); // line 2 curl_setopt($ch[$i],CURLOPT_USERAGENT,$agent); curl_setopt($ch[$i],false); curl_multi_add_handle($multiCurlHandler,$ch[$i]); }