My PHP Curl code is not returning an error or any response text. The JavaScript code I based it off of returns a Json Array.
PHP Curl
header('Access-Control-Allow-Origin: ' . $_SERVER['SERVER_NAME']);
$subscriptionKey = '';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://southcentralus.tts.speech.microsoft.com/cognitiveservices/voices/list');
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Ocp-Apim-Subscription-Key", $subscriptionKey));
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if($response === false)
{
echo 'Curl error: ' . curl_error($ch);
}
else
{
echo 'Operation completed without any errors<br>';
echo "Response: $response";
}
$voices = json_decode($response);
curl_close($ch);
PHP Results
Working Javascript
var request = new XMLHttpRequest();
var subscriptionKey = '';
request.open('GET', 'https://southcentralus.tts.speech.microsoft.com/cognitiveservices/voices/list', true);
request.setRequestHeader("Ocp-Apim-Subscription-Key", subscriptionKey)
request.onload = function() {
if (request.status >= 200 && request.status < 400) {
const response = this.response;
const data = JSON.parse(response);
console.log(data);
} else {
window.console.log(this);
}
};
request.send()
JavaScript Results

I changed CURLOPT_HEADER to true (thanks to Lucas's comments) and now get a 401 error. This puzzles me because it is the exact same URL and Subscription key.
echostatements earlier in your script to see how far through it gets? If neither theiforelseecho statements are being triggered, that suggests there's a problem earlier in the execution. I'd begin with anechoright on line 1 and a few points in between to see how far through it's getting...$responseto be an empty string, because CURLOPT_HEADER isn't true.subscriptionKeydefinitely an empty string in bith cases?