简体   繁体   中英

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. When I replace the URL with google.com it works.

the requested page is htaccess-protected

this is my PHP-Code

$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. It has fetched the requested page. The response you are seeing is the 301 permanent redirect header. 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 will not automatically follow the redirect.

You probably want to use the CURLOPT_FOLLOWLOCATION option. 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. The Location: header can specify a relative or an absolute URL to follow.

You would implement it in PHP like this:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

Here is the documentation for this cURL option.


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.

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. 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.

If possible, get the redirect URL by navigating (via browser) to the old URL and see where you are redirected to. Then use this new, redirected URL in your curl at this line:

curl_setopt($ch, CURLOPT_URL, $newURL);  

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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