[英]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.