PHP – Authentification CURL

MacBook avec code sur un bureau

Pour authentifier une requête cURL en PHP, l’option à connaître est CURLOPT_USERPWD. Elle envoie un couple identifiant / mot de passe au format utilisateur:motdepasse. Authentification basique $ch = curl_init(‘https://exemple.com/api’); curl_setopt($ch, CURLOPT_USERPWD, ‘utilisateur:motdepasse’); curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5); $reponse = curl_exec($ch); if ($reponse === false) { throw new RuntimeException(curl_error($ch)); } curl_close($ch); L’option … Lire la suite