2015-11-05 74 views
1

,所以我試圖讓使用PHP的捲曲連接....當我使用命令行這裏就是獲取返回不能得到圖像

curl -iv https://example.com/image.gif 
* Hostname was NOT found in DNS cache 
* Trying ip.ad.dr.es.ss... 
* Connected to site.com (ip.ad.dr.es.ss) port 443 (#0) 
* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 
* Server certificate: example.com 
* Server certificate: Symantec Class 3 Secure Server CA - G4 
* Server certificate: VeriSign Class 3 Public Primary Certification Authority - G5 
> GET /image.gif HTTP/1.1 
> User-Agent: curl/7.37.1 
> Host: example.com 
> Accept: */* 
> 
< HTTP/1.1 200 OK 
HTTP/1.1 200 OK 
< Content-Type: image/gif 
Content-Type: image/gif 
< Last-Modified: Thu, 14 Jul 2011 22:16:46 GMT 
Last-Modified: Thu, 14 Jul 2011 22:16:46 GMT 
< Accept-Ranges: bytes 
Accept-Ranges: bytes 
< ETag: "09bd8b77342cc1:0" 
ETag: "09bd8b77342cc1:0" 
* Server Microsoft-IIS/7.5 is not blacklisted 
< Server: Microsoft-IIS/7.5 
Server: Microsoft-IIS/7.5 
< X-Powered-By: ASP.NET 
X-Powered-By: ASP.NET 
< X-UA-Compatible: IE=EmulateIE10, requiresActiveX=true 
X-UA-Compatible: IE=EmulateIE10, requiresActiveX=true 
< Date: Thu, 05 Nov 2015 20:57:22 GMT 
Date: Thu, 05 Nov 2015 20:57:22 GMT 
< Content-Length: 43 
Content-Length: 43 
< Set-Cookie: BIGipServerSpace=596747530.20480.0000; path=/ 
Set-Cookie: BIGipServerSpace=596747530.20480.0000; path=/ 

< 
* Connection #0 to host example.com left intact 

而這裏的我如何努力通過PHP

$ch = curl_init(); 
    $url_to_check = 'https://example.com/image.gif'; 
    curl_setopt($ch, CURLOPT_URL, $url_to_check); 
    curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2); 
    curl_setopt($ch, CURLOPT_PORT, 443); 
    curl_exec($ch); 
    $httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
    echo curl_error($ch); 
    echo '||'; 
    echo $httpcode; 
    curl_close($ch); 

訪問它,但隨後它結束了返回

從服務器

空回覆|| 0

什麼我做錯了嗎?我該如何使用SSL通過php CURL獲取圖像?

+0

'$ res = curl_exec($ ch); if($ res === false){die(curl_error($ ch)); }'。如果首先不能獲取http請求,那麼嘗試獲取http狀態碼毫無意義。檢查捲曲級錯誤第一。 –

回答

3

您的PHP使用了哪些cURL版本?也許它不支持在cURL 7.34.0中添加的TLS 1.2。

或者您的CA軟件包可能無法識別您要連接的站點的CA.

嘗試增加:

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 

要查看PHP的捲曲輸出的調試像你在命令行中,你可以添加:

curl_setopt($ch, CURLOPT_VERBOSE, true); 
curl_setopt($ch, CURLOPT_STDERR, fopen('php://output', 'w')); 

這可能會揭示問題的一些光,並且在請求執行後調用var_dump(curl_getinfo($ch));

+0

PHP服務器在7.34.0下使用,但PHP捲曲能夠正確獲取https://en.wikipedia.org/static/favicon/wikipedia.ico,即使它也使用TLS 1.2 .....任何想法? – pillarOfLight

+0

@pillarOfLight en.wikipedia.org支持TLS 1.0,TLS 1.1和TLS 1.2兼容性(無SSLv2或SSLv3),這就是您的curl能夠獲取它的原因。如果一個站點僅支持* tls 1.2,那麼cURL <7.34.0將無法獲取它。您需要升級您的PHP cURL模塊(或者如果它內置到PHP中,請升級PHP並使用更新版本的cURL和OpenSSL進行編譯)。 – drew010

+0

所以服務器的捲曲版本是\t 7.19.7 ....在https://www.ssllabs.com檢查我感興趣的網站後,事實證明它們支持TLS 1.2,TLS 1.1和TLS 1.0 .....這是否意味着curl 7.19.7甚至不支持TLS 1.0? – pillarOfLight