这个debug-verbose-info是什么意思?



我试图通过cURL+PHP获得页面的内容,但它没有给我任何回报。当我用google.com替换URL时,它可以工作。

请求的页面是受http保护的

这是我的php代码

$login = 'admin';
$password = 'xxxxx';
$ch = curl_init();        
curl_setopt($ch, CURLOPT_URL, $_REQUEST['url']);      
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);    
curl_setopt($ch, CURLOPT_VERBOSE, true);
$verbose = fopen('bla.txt', 'w+');
curl_setopt($ch, CURLOPT_STDERR, $verbose);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_USERPWD, "$login:$password");
$output = curl_exec($ch);        
curl_close($ch);  
echo $output;

这是verbose-info:

* Hostname was NOT found in DNS cache
*   Trying xxx.xxx.xxx.xxx...
* Connected to xxxxxxxxx (xxx.xxx.xxx.xxx) port 80 (#0)
* Server auth using Basic with user 'admin'
> GET /mypage.php HTTP/1.1
Authorization: Basic YWRtaW46cXdlcnR6dTE=
Host: xxxxxxxxxxxxxx.de
Accept: */*

< HTTP/1.1 301 Moved Permanently
< Date: Fri, 16 Sep 2016 13:44:28 GMT
* Server Apache is not blacklisted
< Server: Apache
< X-Powered-By: PHP/5.4.45
< Expires: Thu, 19 Nov 1981 08:52:00 GMT
< Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
< Pragma: no-cache
< Set-Cookie: PHPSESSID=23cd31457358a63a1b32b86992e906bf2; path=/; HttpOnly
< Location: xxxxxxxxxxxxxxxxxxxxxxx
< Content-Length: 0
< Connection: close
< Content-Type: text/html; charset=UTF-8
< 
* Closing connection 0
谁能告诉我怎么了?

cURL正在停止,因为就它而言,工作已经完成。它已经获取了所请求的页面。您看到的响应是301永久重定向头。如果您在浏览器中访问了最初为cURL请求指定的URL,它将自动跟随URL到达指定的目的地。cURL不会自动跟随重定向。

您可能希望使用CURLOPT_FOLLOWLOCATION选项。手册将其描述为:

设置为1的长参数告诉库遵循服务器在3xx响应中作为HTTP头的一部分发送的任何Location:头。Location:标头可以指定要跟随的相对URL或绝对URL。

你可以在PHP中这样实现它:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

下面是这个cURL选项的文档。


如果你不想使用这个选项,你也可以通过在301 HTTP状态码响应中指定的位置,并使用这个作为你的URL来手动重定向你的页面。

尝试添加CURLOPT_FOLLOWLOCATION并阅读更多关于CURLOPT_FOLLOWLOCATION和safe_mode: https://stackoverflow.com/a/21234822/6797531

HTTP状态码301表示您试图获取内容的页面的URL已移动到新的URL。您无法使用旧URL检索此网站的内容,但您已被通知该网站现在可以通过重定向URL访问。

如果可能的话,通过导航(通过浏览器)获得重定向URL到旧的URL,看看你被重定向到哪里。然后在curl中使用这个新的重定向URL:

curl_setopt($ch, CURLOPT_URL, $newURL);  

最新更新