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的