繁体   English   中英

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

[英]what does this debug-verbose-info mean?

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

请求的页面受 htaccess 保护

这是我的 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;

这是详细信息:

* 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。

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

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

这是此 cURL 选项的文档


如果您不想使用此选项,您还可以通过获取 301 HTTP 状态代码响应中指定的位置并将其用作您的 URL 来手动重定向您的页面。

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

如果可能,通过导航(通过浏览器)到旧 URL 来获取重定向 URL,并查看您被重定向到的位置。 然后在 curl 的这一行使用这个新的、重定向的 URL:

curl_setopt($ch, CURLOPT_URL, $newURL);  

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

暂无
暂无

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

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