I am fairly new to PHP and I am trying to use the Microsoft OCR API. I already have my key and it is working as I have tested here: https://brazilsouth.dev.cognitive.microsoft.com/docs/services/unified-vision-apis-public-preview-2023-04-01-preview/operations/61d65934cd35050c20f73ab6/console.
So what I am trying to do is make a PHP API request. I cannot install any libraries to do this as it is a requirement for what I am doing. So I am trying to use the CURL and because of my newbieness in PHP don´t know if this is the best approach nor whats wrong with it.
The request the above mentioned webpage is as follow:

Here is the code that I have:
<?php
class Computer_Vision{
public function __construct(){
$this->azure_ocr="https://brazilsouth.api.cognitive.microsoft.com/computervision/imageanalysis:analyze?api-version=2023-04-01-preview&features=read&language=pt HTTP/1.1";
$this->subscription_key="blahblahblah";
}
public function recognize($image_url){
$data = array("url" => $image_url);
$azure_url = $this->azure_ocr;
print($azure_url . "<br/>");
$key=$this->subscription_key;
$data_string = json_encode($data);
print($data_string . "<br/>");
$curl = curl_init($azure_url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($curl, CURLOPT_POST, 1 );
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Ocp-Apim-Subscription-Key:'.$key
));
$response = curl_exec($curl);
print("response: " . $response . "<br/>");
if(curl_error($curl)) {
print('error:' . curl_error($curl));
} else {
$json_object = json_decode($response, true);
print("json_object: " . $json_object);
}
curl_close($curl);
}
}
?>
on my index.php I have:
<?php
$azure = new Computer_Vision();
$image_url = "https://portal.vision.cognitive.azure.com/dist/assets/OCR1-6dda571d.jpg";
$ocr = $azure->recognize($image_url, "ocr");
?>
the code above doesn´t give me any errors (at least it does not enter the curl_error condition) but it gives me an empty response
what would be the best way to do this? what I am doing wrong? any help is more than appreciated .