A provider has an API that would be the following
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, "xxxxx:yyyyyyy");
curl_setopt($ch, CURLOPT_URL, "https://xxxx.yyyy.com/api/clientes");
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
$retorno = curl_exec($ch);
$error = curl_errno($ch);
if ($error) {
echo "Error; " . $error;
} else {
curl_close($ch);
return $retorno;
}
the thing is that I can't access the data, and the provider doesn't support JS, it only supports PHP, in php it works fine for me, but what I want is to access the data directly through the front and simply show them.
I attach the code that I am running:
(async () => {
fetch("https://xxxx.dominio.com/api/clientes/1", {
mode: "cors",
method: "GET",
headers: {
Authorization: "Basic xxxxxx:yyyyyyyy",
},
})
.then((response) => response.json())
.then((json) => console.log(json));
})();
I execute the code from the client, in my browser. And I have the CORS plugin enabled and add mode: "cors" to the header.
in fact with the PAW for mac application, I create the connection and it gives me ok, it shows me the logs but if I run it from the js in the browser it fails. I attach the exported Fetch JS, if you try it it will not work because it is limited to ip.
Because you don't consume a PHP file that executes the curl and you return the data in json format or similar to your Frontend in that way you shouldn't have problems, it's easier and more viable to do it that way.
Instead of fetch them you fetch that PHP file .
I hope my answer helps you.
the provider has browser JS access enabled. Requests per client and not per server.
Thank you