Php Curl获取响应空结果
你好, 我正在尝试使用CURL从网站获取页面,以下是我的代码: 我的带有CURL设置的PHP文件Php Curl获取响应空结果,php,curl,https,get,header,Php,Curl,Https,Get,Header,你好, 我正在尝试使用CURL从网站获取页面,以下是我的代码: 我的带有CURL设置的PHP文件 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url ); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300); curl_setopt
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 300);
curl_setopt($ch, CURLOPT_TIMEOUT, 300); //timeout in seconds
$resultcurl = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
在经历了通过Stackoverflow的CURL之后,我得到了一篇帖子,建议如下
$header = get_headers('https://www.websitedomain.com/somepage');
echo '<pre>';
print_r($header);
echo '</pre>';
内容长度始终显示为“10”,当我直接通过浏览器访问页面时,它会工作!有人能帮忙吗强>
HTTP/1.1 301永久移动
你被重定向了。您需要遵循它,哪些浏览器会自动执行,但哪些PHP的cURL库在默认情况下不会执行。您可以通过以下方式进行更改:
谢谢@quentin!
Array
(
[0] => HTTP/1.1 301 Moved Permanently
[1] => Cache-Control: no-cache, must-revalidate
[2] => Content-Type: text/html; charset=UTF-8
[3] => Date: Thu, 21 Jun 2018 06:50:00 GMT
[4] => Expires: Sun, 19 Nov 1978 05:00:00 GMT
[5] => Location: https://www.websitedomain.com/somepage
[6] => Server: Apache/2.4.33 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.36
[7] => X-Content-Type-Options: nosniff
[8] => X-Content-Type-Options: nosniff
[9] => X-Drupal-Cache: MISS
[10] => X-Powered-By: PHP/5.6.36
[11] => Content-Length: 10
[12] => Connection: Close
[13] => HTTP/1.1 200 OK
[14] => Cache-Control: no-cache, must-revalidate
[15] => Content-Language: en
[16] => Content-Type: text/html; charset=utf-8
[17] => Date: Thu, 21 Jun 2018 06:50:00 GMT
[18] => Expires: Sun, 19 Nov 1978 05:00:00 GMT
[19] => Link: ,,,,,
[20] => Server: Apache/2.4.33 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.36
[21] => Vary: Accept-Encoding
[22] => X-Content-Type-Options: nosniff
[23] => X-Content-Type-Options: nosniff
[24] => X-Drupal-Cache: MISS
[25] => X-Generator: Drupal 7 (http://drupal.org)
[26] => X-Powered-By: PHP/5.6.36
[27] => X-UA-Compatible: IE=edge,chrome=1
[28] => Connection: Close
)
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);