简体   繁体   English

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

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

I try to get the content of a page via cURL+PHP, but it gives me nothing back.我尝试通过 cURL+PHP 获取页面的内容,但它没有给我任何回报。 When I replace the URL with google.com it works.当我用google.com替换 URL 时,它可以工作。

the requested page is htaccess-protected请求的页面受 htaccess 保护

this is my PHP-Code这是我的 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;

this is the 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

can someone tell me what is wrong??有人能告诉我有什么问题吗??

cURL is stopping because as far as it is concerned, the job is done. cURL 正在停止,因为就它而言,工作已经完成。 It has fetched the requested page.它已获取请求的页面。 The response you are seeing is the 301 permanent redirect header.您看到的响应是 301 永久重定向标头。 If you visited the URL you originally specified for your cURL request in a browser it would automatically follow the URL to the destination specified.如果您在浏览器中访问了最初为 cURL 请求指定的 URL,它将自动跟随 URL 到达指定的目的地。 cURL will not automatically follow the redirect. cURL 不会自动跟随重定向。

You probably want to use the CURLOPT_FOLLOWLOCATION option.您可能想要使用CURLOPT_FOLLOWLOCATION选项。 The manual describes this as: 该手册描述为:

A long parameter set to 1 tells the library to follow any Location: header that the server sends as part of a HTTP header in a 3xx response.设置为 1 的长参数告诉库遵循服务器在 3xx 响应中作为 HTTP 标头的一部分发送的任何 Location: 标头。 The Location: header can specify a relative or an absolute URL to follow. Location: 标头可以指定要遵循的相对或绝对 URL。

You would implement it in PHP like this:你可以像这样在 PHP 中实现它:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

Here is the documentation for this cURL option.这是此 cURL 选项的文档


If you don't want to use this option, you could also manually redirect your page by taking the location specified in the 301 HTTP status code response and using this as your URL instead.如果您不想使用此选项,您还可以通过获取 301 HTTP 状态代码响应中指定的位置并将其用作您的 URL 来手动重定向您的页面。

HTTP status code 301 means that the URL of the page for which you are trying to get content has moved to a new URL. HTTP 状态代码 301 表示您尝试获取内容的页面的 URL 已移至新 URL。 You cannot retrieve the contents of this website using the old URL, but you have been notified the website now is accessible at the redirect URL.您无法使用旧 URL 检索此网站的内容,但您已收到通知,现在可以通过重定向 URL 访问该网站。

If possible, get the redirect URL by navigating (via browser) to the old URL and see where you are redirected to.如果可能,通过导航(通过浏览器)到旧 URL 来获取重定向 URL,并查看您被重定向到的位置。 Then use this new, redirected URL in your curl at this line:然后在 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