0
I’m trying to connect my application with a PHP API.
I have the following Ionic code in which the authentication is done by Token:
login(data:IUsuario) {
let tokenBasic = btoa(data.usuario + ":" + data.senha);
let headerBasic = {
"headers": {
'Authorization': "Basic " + tokenBasic,
'Content-Type': 'application/json',
'cache-control': 'no-cache'
}
};
return this.http.get<any>(this.url + '/AppLogin', headerBasic);
}
In my PHP API the code already contains headers for CORS:
<?php
header('Access-Control-Allow-Headers: "Origin, X-Requested-With, Content-Type, Accept"');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS');
header('Content-Type: application/json; charset=utf8');
echo json_encode((object) array( 'Auth'=> 'true', 'Data'=>'04/08/2019', 'Usuario'=> 'teste'));
?>
But when making any query by the browser, I get the following error:
On the network:
Dear Gustavo, it seems that using a FW of routes, because the url is not final . php, then probably your headers have not even been sent, with the details of the question nor have to help you, have to explain right what you did to get help you
– Guilherme Nascimento
Guilherme, in this case I’m using the Codeigniter framework in PHP, but the PHP code I mentioned, I just wanted to simplify accessing only it (test.php) without routes, so as soon as the headers work in this file I apply throughout the framework.
– Gustavo
By the answer the app did not work no, do the test by opening the URL directly via browser, probably something failed in your back-end
– Guilherme Nascimento