我尝试使用php和curl获取html页面https://trimet.ru/1cengine/site/。
但我得到循环重定向:
请求http s 返回
301永久移动 - 位置:http://trimet.ru/1cengine/site/
请求http返回
302暂时移动 - 位置:http s ://trimet.ru/1cengine/site/
发送请求的所有服务器都不会发生循环重定向。起初我认为CURL和OpenSSL版本存在问题,但更新没有帮助。
PHP代码:
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, 'https://trimet.ru/1cengine/site/');
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT,10);
curl_setopt($ch, CURLOPT_TIMEOUT,60);
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.1) Gecko/20090716 Ubuntu/9.04 (jaunty) Shiretoko/3.5.1');
curl_setopt($ch, CURLOPT_VERBOSE,2);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_MAXREDIRS,7);
curl_setopt($ch, CURLOPT_AUTOREFERER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
CURL DEBUG OUTPUT:
* About to connect() to trimet.ru port 443 (#0)
* Trying 2a03:6f00:1::5c35:6090...
* connected
* Connected to trimet.ru (2a03:6f00:1::5c35:6090) port 443 (#0)
* successfully set certificate verify locations:
* CAfile: none
CApath: /etc/ssl/certs
* SSL connection using ECDHE-RSA-AES128-GCM-SHA256
* Server certificate:
* subject: C=RU; ST=Saint-Petersburg; L=Saint Petersburg; O=TimeWeb Company Limited; CN=*.timeweb.ru
* start date: 2014-11-28 00:00:00 GMT
* expire date: 2016-01-27 23:59:59 GMT
* issuer: C=US; O=thawte, Inc.; CN=thawte SSL CA - G2
* SSL certificate verify ok.
> GET /1cengine/site/ HTTP/1.1
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.1) Gecko/20090716 Ubuntu/9.04 (jaunty) Shiretoko/3.5.1
Host: trimet.ru
Accept: text/html,application/xhtml+xml,application/xml;q=0.9
Accept-Language: ru,en-us;q=0.7,en;q=0.7
Accept-Charset: utf-8,windows-1251;q=0.7,*;q=0.5
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.6.3
< Date: Sat, 26 Dec 2015 21:26:59 GMT
< Content-Type: text/html
< Content-Length: 184
< Connection: keep-alive
< Location: http://trimet.ru/1cengine/site/
<
* Ignoring the response-body
* Connection #0 to host trimet.ru left intact
* Issue another request to this URL: 'http://trimet.ru/1cengine/site/'
* About to connect() to trimet.ru port 80 (#1)
* Trying 2a03:6f00:1::5c35:6090...
* connected
* Connected to trimet.ru (2a03:6f00:1::5c35:6090) port 80 (#1)
> GET /1cengine/site/ HTTP/1.1
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.1) Gecko/20090716 Ubuntu/9.04 (jaunty) Shiretoko/3.5.1
Host: trimet.ru
Referer: https://trimet.ru/1cengine/site/
Accept: text/html,application/xhtml+xml,application/xml;q=0.9
Accept-Language: ru,en-us;q=0.7,en;q=0.7
Accept-Charset: utf-8,windows-1251;q=0.7,*;q=0.5
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 302 Moved Temporarily
< Server: nginx/1.6.3
< Date: Sat, 26 Dec 2015 21:26:59 GMT
< Content-Type: text/html
< Content-Length: 160
< Connection: keep-alive
< Location: https://trimet.ru/1cengine/site/
<
* Ignoring the response-body
* Connection #1 to host trimet.ru left intact
* Issue another request to this URL: 'https://trimet.ru/1cengine/site/'
* Re-using existing connection! (#0) with host (nil)
* Connected to (nil) (2a03:6f00:1::5c35:6090) port 443 (#0)
> GET /1cengine/site/ HTTP/1.1
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.1) Gecko/20090716 Ubuntu/9.04 (jaunty) Shiretoko/3.5.1
Host: trimet.ru
Referer: http://trimet.ru/1cengine/site/
Accept: text/html,application/xhtml+xml,application/xml;q=0.9
Accept-Language: ru,en-us;q=0.7,en;q=0.7
Accept-Charset: utf-8,windows-1251;q=0.7,*;q=0.5
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 301 Moved Permanently
< Server: nginx/1.6.3
< Date: Sat, 26 Dec 2015 21:26:59 GMT
< Content-Type: text/html
< Content-Length: 184
< Connection: keep-alive
< Location: http://trimet.ru/1cengine/site/
<
* Ignoring the response-body
* Connection #0 to host (nil) left intact
* Issue another request to this URL: 'http://trimet.ru/1cengine/site/'
* Re-using existing connection! (#1) with host (nil)
* Connected to (nil) (2a03:6f00:1::5c35:6090) port 80 (#1)
> GET /1cengine/site/ HTTP/1.1
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.1) Gecko/20090716 Ubuntu/9.04 (jaunty) Shiretoko/3.5.1
Host: trimet.ru
Referer: https://trimet.ru/1cengine/site/
Accept: text/html,application/xhtml+xml,application/xml;q=0.9
Accept-Language: ru,en-us;q=0.7,en;q=0.7
Accept-Charset: utf-8,windows-1251;q=0.7,*;q=0.5
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 302 Moved Temporarily
< Server: nginx/1.6.3
< Date: Sat, 26 Dec 2015 21:26:59 GMT
< Content-Type: text/html
< Content-Length: 160
< Connection: keep-alive
< Location: https://trimet.ru/1cengine/site/
<
* Ignoring the response-body
* Connection #1 to host (nil) left intact
* Issue another request to this URL: 'https://trimet.ru/1cengine/site/'
* Re-using existing connection! (#0) with host (nil)
* Connected to (nil) (2a03:6f00:1::5c35:6090) port 443 (#0)
> GET /1cengine/site/ HTTP/1.1
User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.1) Gecko/20090716 Ubuntu/9.04 (jaunty) Shiretoko/3.5.1
Host: trimet.ru
Referer: http://trimet.ru/1cengine/site/
Accept: text/html,application/xhtml+xml,application/xml;q=0.9
Accept-Language: ru,en-us;q=0.7,en;q=0.7
Accept-Charset: utf-8,windows-1251;q=0.7,*;q=0.5
* additional stuff not fine transfer.c:1037: 0 0
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 301 Moved Permanently