Как я могу использовать Restful API, используя file_get_contents и дайджест-аутентификацию в php.
Я знаю, что могу получить к нему доступ с помощью curl
$ch = curl_init('http://webservicesurlhere.com');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
//curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_USERPWD, $username . ":" . $password);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json'
//,
//'Content-Length: ' . strlen($data_string)
)
);
$resources = curl_exec($ch);
curl_close($ch);
Но мой Текущий код написан с использованием file_get_contents. Доступ к аутентификации основного типа можно получить, используя приведенный ниже код.
$opts = array('http' =>
array(
'method' => 'POST',
'header' => "Content-Type: text/xml\r\n".
"Authorization: Basic ".base64_encode("$https_user:$https_password")."\r\n",
'content' => $body,
'timeout' => 60
)
);
$context = stream_context_create($opts);
$url = 'https://'.$https_server;
$result = file_get_contents($url, false, $context, -1, 40000);
Кто-нибудь знает, как я могу использовать file_get_contents для аутентификации типа Digest?
Связанная информация, которую я нахожу.