[英]IIS or Apache Web Server Authentication with PHP curl
我在Windows 10上使用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和cURL 7.51.0
IIS設置為FastCGI
未設置CA認證。
注意:也可以通過添加curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,FALSE)來繞過
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.