2016-11-25 143 views
2

我使用PHP和curl在Windows 10上設置了IIS和Apache Web Server。以下代碼正常工作。使用PHP curl的IIS或Apache Web服務器身份驗證

<?php 

    $url = "http://domain.com"; 

    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 30); //Timeout after 30 seconds 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //Get status code 

    $response = curl_exec($ch); 

    curl_close($ch); 

    echo $response; 

?> 

當我添加驗證,它不起作用。

<?php 

    $username = "username"; 
    $password = "password"; 
    $url = "https://domain.com/api/v2/orders/count"; 

    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 30); //Timeout after 30 seconds 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
    curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); 

    $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //Get status code 

    $response = curl_exec($ch); 

    curl_close($ch); 

    echo $response; 

?> 

當我在GoDaddy服務器上運行它時,此代碼正常工作。

的代碼位於http://localhost/test.php
我有PHP NTS 7.0.13和捲曲7.51.0
IIS被設置爲FastCGI的

回答

0

CA證書不成立。

  • 轉到[pathToYourPHP] \演員\ SSL
  • 創建一個名爲cacert.pem
  • 文件
  • 轉到CA certificates extracted from Mozilla
  • 點擊cacert.pem
  • 複製的內容並把它放在你的cacert.pem
  • 在php.ini,將路徑設置爲curl.cainfo = 「[pathToYourPHP] \額外\ SSL \ cacert.pem」

注意:這也可以通過添加curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,FALSE)來繞過