Reputation: 65
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;
});
}
Upvotes: 3
Views: 239
Reputation: 4738
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,
Upvotes: 2