3

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; 
   });
  }
1
  • 1
    Please try to add options method in allowedMethods array and try again hope it will work Commented May 29, 2018 at 5:13

1 Answer 1

2

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,
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.