Я использую Haveibeenpwned API, но у меня проблемы с постоянными ошибками 403.Я пытаюсь использовать Curl и file_get_contents, но у меня такие же результаты ...
function Conn_mail($email){
$headers = [
'User-Agent: Meu user agent'
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"https://haveibeenpwned.com/api/v2/breachedaccount/{$email}");
curl_setopt($ch, CURLOPT_HEADER,true); //Retorna o Header na saída
//if($headers){
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//}
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
$response = curl_exec($ch);
return $response;
/*var_dump($response);
if (!$response){
echo curl_error($ch);
}*/
}
$json_hibp = Conn_mail('whatever@email.com');
echo $json_hibp;
И
<code> function Conn_mail($email){
$context_options = array(
'http' => array('user_agent' => 'custom user agent string')
);
$context = stream_context_create($context_options);
$con = file_get_contents("https://haveibeenpwned.com/api/v2/breachedaccount/{$email}",false,$context);
echo "<pre>";
print_r($http_response_header);
echo "
"; $ retorno = $ http_response_header [0]; if ($ retorno == 'HTTP/1.1 200 OK ') {$ ret =' 200 ';} elseif ($ retorno ==' HTTP / 1.1 404 Not Found ') {$ ret =' 404 ';} else {$ ret = $ retorno;} return $ret;} $ json_hibp = Conn_mail ('whwhat@email.com '); echo $ json_hibp;
Оба кода содержат заголовок «User Agent», но API Haveibeenpwned возвращает ошибку 403 (которая возвращается толькоесли пользовательский агент отсутствует ...)
Что не так?
Спасибо