I'm developing a hybrid app with Ionic 3 and Laravel as Back-end. I had to host the backend on an online server (000webhost) to do some in-app testing, that's when it started my problems. Before hosting, using my computer as a server (localhost), I was able to make any type of request through Ionic providers. Using webhost hosting, I can only make GET requests, any other type of request give me the MethodNotAllowedHttpException error. Trying to make the same type of request using the postman it is processed successfully.
My configuration file cors.php is as follow:
<?php
return [
/*
|--------------------------------------------------------------------------
| Laravel CORS
|--------------------------------------------------------------------------
|
| allowedOrigins, allowedHeaders and allowedMethods can be set to array('*')
| to accept any value.
|
*/
'supportsCredentials' => false,
'allowedOrigins' => ['*'],
'allowedOriginsPatterns' => [],
'allowedHeaders' => ['*'],
'allowedMethods' => ['GET', 'POST', 'PUT', 'DELETE'],
'exposedHeaders' => [],
'maxAge' => 0,
];
he route I'm trying to access:
Route::post ('ajudado/', 'AjudadoController@set_ajudado');
the provider method in Ionic:
set_ajudado(dados):Promise<any>
{
return this.http.post(this.url, dados).toPromise().then(function(data){
return data;
});
}
You will need to allow the OPTIONS method in your CORS rules.
'supportsCredentials' => false,
'allowedOrigins' => ['*'],
'allowedOriginsPatterns' => [],
'allowedHeaders' => ['*'],
'allowedMethods' => ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
'exposedHeaders' => [],
'maxAge' => 0,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With